- Get link
- X
- Other Apps
This simple PHP function is used to Remove Duplicate QueryStrings from URL.
Function:
function rnsQueryString_dupremov($qstring){
if(!empty($qstring)) {
$vars = explode('&', $qstring);
$final = array();
if(!empty($vars)) {
foreach($vars as $var) {
$parts = explode('=', $var);
$key = $parts[0];
if(!empty($parts[1])) { $val = $parts[1]; } else {$val="";}
if(!array_key_exists($key, $final) && !empty($val))
$final[$key] = $val;
}
}
return http_build_query($final);
} else { return false; }
}
Example:
$path="property_add.php?id=3&aa=aa&b=123&b=123&aa=aa";
define('RNSFIWQ', property_add.'?'.rnsQueryString_dupremov($_SERVER['QUERY_STRING']));
or
define('RNSFIWQ', basename($_SERVER['SCRIPT_NAME'].'?'.rnsQueryString_dupremov($_SERVER['QUERY_STRING']));
echo RNSFIWQ;
Output:
property_add?id=3&aa=aa&b=123
Function:
function rnsQueryString_dupremov($qstring){
if(!empty($qstring)) {
$vars = explode('&', $qstring);
$final = array();
if(!empty($vars)) {
foreach($vars as $var) {
$parts = explode('=', $var);
$key = $parts[0];
if(!empty($parts[1])) { $val = $parts[1]; } else {$val="";}
if(!array_key_exists($key, $final) && !empty($val))
$final[$key] = $val;
}
}
return http_build_query($final);
} else { return false; }
}
Example:
$path="property_add.php?id=3&aa=aa&b=123&b=123&aa=aa";
define('RNSFIWQ', property_add.'?'.rnsQueryString_dupremov($_SERVER['QUERY_STRING']));
or
define('RNSFIWQ', basename($_SERVER['SCRIPT_NAME'].'?'.rnsQueryString_dupremov($_SERVER['QUERY_STRING']));
echo RNSFIWQ;
Output:
property_add?id=3&aa=aa&b=123
Comments
Post a Comment