/ Published in: PHP
Current URL http://www.example.com/page.php?p=5&show=list&style=2 and after
$url = modify_url(array('p' => 4, 'show' => 'column'));
URL will become http://www.example.com/page.php?p=4&show=column&style=2
$url = modify_url(array('p' => 4, 'show' => 'column'));
URL will become http://www.example.com/page.php?p=4&show=column&style=2
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function modify_url($mod){ $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; if (!$_SERVER['QUERY_STRING']) {$queryStart = "?";} else {$queryStart = "&";} // modify/delete data foreach($query as $q) { { if($mod[$key]) { } else { } } } // add new data foreach($mod as $key => $value) { { $url .= $queryStart.$key.'='.$value; } } return $url; }
URL: http://www.phpsnippets.info/easily-modify-url-parameters