示例#1
0
 public function testBuildGETString()
 {
     $this->assertEquals('', PU_BuildGETString(array()));
     $this->assertEquals('', PU_BuildGETString(array(), '&'));
     $this->assertEquals('?a=1', PU_BuildGETString(array('a' => 1)));
     $this->assertEquals('?a=1', PU_BuildGETString(array('a' => 1), '&'));
     $this->assertEquals('?a=1&b=test', PU_BuildGETString(array('a' => 1, 'b' => 'test')));
     $this->assertEquals('?a=1&b=test', PU_BuildGETString(array('a' => 1, 'b' => 'test'), '&'));
     $this->assertEquals('?a=%26%20%C3%A9&b=test', PU_BuildGETString(array('a' => '& é', 'b' => 'test')));
     $this->assertEquals('?a=%26%20%C3%A9&b=test', PU_BuildGETString(array('a' => '& é', 'b' => 'test'), '&'));
 }
示例#2
0
/**
 * Build a url with GET parameters
 *
 * @param string|array $target (optional) string: the target script url (current script if missing)
 * @param array $includeInGet	(optional) array of pairs: parameters to add as GET in the url
 * @param array $excludeFromGet (optional) array of strings: parameters to remove from GET in the url
 * @return string the built url
 *
 * @version 1.1
 * @author greg
 *
 * @date 20100930 (v1.1) (greg) $target parameter can now be an array resulting from php's parse_url function
 */
function PU_BuildURL($target = null, $includeInGet = null, $excludeFromGet = null, $glue = '&')
{
    if (is_null($target)) {
        $target = $_SERVER["REQUEST_URI"];
    }
    if (!is_array($target)) {
        $target = parse_url($target);
    }
    if (empty($target['query'])) {
        $tarGET = $_GET;
    } else {
        parse_str($target['query'], $tarGET);
        $tarGET = array_merge($_GET, $tarGET);
    }
    $myGET = PU_BuildGETArray($tarGET, $includeInGet, $excludeFromGet);
    $target['query'] = PU_BuildGETString($myGET, $glue);
    $target = PU_buildParsedURL($target);
    return $target;
}