PHP Classes

File: classes/http/http-helper.php

Recommend this page to a friend!
  Classes of Gonzalo Chumillas   HttpRequest   classes/http/http-helper.php   Download  
File: classes/http/http-helper.php
Role: Class source
Content type: text/plain
Description: Class source
Class: HttpRequest
Send HTTP requests to remote servers
Author: By
Last change:
Date: 9 years ago
Size: 1,258 bytes
 

Contents

Class file image Download
<?php
/**
 * This file is part of Soloproyectos common library.
 *
 * @author Gonzalo Chumillas <gchumillas@email.com>
 * @license https://github.com/soloproyectos/php.common-libs/blob/master/LICENSE BSD 2-Clause License
 * @link https://github.com/soloproyectos/php.common-libs
 */
namespace com\soloproyectos\common\http;
use
com\soloproyectos\common\text\TextHelper;

/**
 * Class HttpHelper.
 *
 * This class is used to send POST requests.
 *
 * @package Http
 * @author Gonzalo Chumillas <gchumillas@email.com>
 * @license https://github.com/soloproyectos/php.common-libs/blob/master/LICENSE BSD 2-Clause License
 * @link https://github.com/soloproyectos/php.common-libs
 */
class HttpHelper
{
   
/**
     * Appends parameters to a given url.
     *
     * For example:
     * ```php
     * echo HttpHelper::addParams("http://www.mysite.php", array("username" => "John", "id" => 101));
     * ```
     *
     * @param string $url URL
     * @param array $params Associative array of parameters
     *
     * @return strings.
     */
   
static public function addParams($url, $params)
    {
       
$query = parse_url($url, PHP_URL_QUERY);
        return
$url . (TextHelper::isEmpty($query)? "?" : "&") . http_build_query($params);
    }
}