Consider a php script visited with URL of foo?q=some&s=3&d=new. I wonder if there is a paractical method for parsing the url to create links with new variable (within php page). For example foo?q=**another-word**&s=3&d=new or foo?q=another-word&s=**11**&d=new
I am thinking of catching the requested URL by $_SERVER[‘REQUEST_URI’] then parsing with regex; but this is not a good idea in practice. There should be a handy way to parse variables attached to the php script. In fact, inverse action of GET method.
The
$_GETvariable contains an already parsed array of the current query string. The array union operator+makes it easy to merge new values into that.http_build_queryputs them back together into a query string:If you need more parsing of the URL to get
'foo', useparse_urlon theREQUEST_URI.