note 125617 deleted from function.parse-url by cmb
| From: | cmb@php.net | Date: | Sun, 20 Dec 2020 11:34:43 +0000 |
| Subject: | note 125617 deleted from function.parse-url by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-216009@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
Here's a piece of code that modifies, replaces or removes the url query. This can typically
used in paging situations where there are more parameters than the page.
<?php
function modify_url($mod)
{
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$query = explode("&", $_SERVER['QUERY_STRING']);
// modify/delete data
foreach($query as $q)
{
list($key, $value) = explode("=", $q);
if(array_key_exists($key, $mod))
{
if($mod[$key])
{
$url = preg_replace('/'.$key.'='.$value.'/',
$key.'='.$mod[$key], $url);
}
else
{
$url = preg_replace('/&?'.$key.'='.$value.'/',
'', $url);
}
}
}
// add new data
foreach($mod as $key => $value)
{
if($value && !preg_match('/'.$key.'=/', $url))
{
$url .= '&'.$key.'='.$value;
}
}
return $url;
}
https://www.dreams-image.com