note 125617 added to function.parse-url

From: Date: Sat, 19 Dec 2020 23:55:16 +0000
Subject: note 125617 added to function.parse-url
Groups: php.notes 
Request: Send a blank email to php-notes+get-216005@lists.php.net to get a copy of this message
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 ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.159.165 (proxied: 185.95.204.103) ---- Manual Page -- http://php.net/manual/en/function.parse-url.php Edit -- https://master.php.net/note/edit/125617 Del: integrated -- https://master.php.net/note/delete/125617/integrated Del: useless -- https://master.php.net/note/delete/125617/useless Del: bad code -- https://master.php.net/note/delete/125617/bad+code Del: spam -- https://master.php.net/note/delete/125617/spam Del: non-english -- https://master.php.net/note/delete/125617/non-english Del: in docs -- https://master.php.net/note/delete/125617/in+docs Del: other reasons-- https://master.php.net/note/delete/125617 Reject -- https://master.php.net/note/reject/125617 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#216005) next »