create-query-string
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
function url( $f_szUrlInfo = '', $f_bXHTMLalize = false )
{
// If empty or no string inputted, return the current url
if ( 0 == strlen(trim((string)$f_szUrlInfo)) )
{
return 0 < count($_GET) ? '?'.$_SERVER['QUERY_STRING'] : basename($_SERVER['SCRIPT_NAME']);
}
$szParamDelimiter = $f_bXHTMLalize ? '&' : '&';
// Create first (old) part
$arrQueryParams = $_GET;
// Create next (new) part
$arrOldParts = explode("&", $f_szUrlInfo);
foreach ( $arrOldParts AS $szParamPart )
{
list($key, $val) = explode("=", $szParamPart, 2);
// this is new and not urlencode()d, so encode it now
$arrQueryParams[urlencode($key)] = urlencode($val);
}
// The first char of the query_string is a '?'
$szUrl = '?';
foreach ( $arrQueryParams AS $szKey => $szVal )
{
$szUrl .= $szKey . '=' . $szVal . $szParamDelimiter;
}
return substr( $szUrl, 0, -1*strlen($szParamDelimiter) );
}
?>
function url( $f_szUrlInfo = '', $f_bXHTMLalize = false )
{
// If empty or no string inputted, return the current url
if ( 0 == strlen(trim((string)$f_szUrlInfo)) )
{
return 0 < count($_GET) ? '?'.$_SERVER['QUERY_STRING'] : basename($_SERVER['SCRIPT_NAME']);
}
$szParamDelimiter = $f_bXHTMLalize ? '&' : '&';
// Create first (old) part
$arrQueryParams = $_GET;
// Create next (new) part
$arrOldParts = explode("&", $f_szUrlInfo);
foreach ( $arrOldParts AS $szParamPart )
{
list($key, $val) = explode("=", $szParamPart, 2);
// this is new and not urlencode()d, so encode it now
$arrQueryParams[urlencode($key)] = urlencode($val);
}
// The first char of the query_string is a '?'
$szUrl = '?';
foreach ( $arrQueryParams AS $szKey => $szVal )
{
$szUrl .= $szKey . '=' . $szVal . $szParamDelimiter;
}
return substr( $szUrl, 0, -1*strlen($szParamDelimiter) );
}
?>