PHP url parameter acquisition problem, how to quickly obtain the required parameter http://www.abc.com/content/5176.asp? Page = 1 & 5176__2 # p
The current url is the link
I need to generate a link on the current page.
Http://www.abc.com/content/5176.asp? Page = 1 & author = 10000
How to quickly complete ??
My approach is:
Function ghref ($ param) {$ url = "http ://". $ _ SERVER ['http _ host']. $ _ SERVER ['request _ URI ']; // Obtain the url $ query_str = parse_url ($ url, PHP_URL_QUERY); // obtain the value after the url question mark, not including # $ query_str = explode ("&", $ query_str); // cut into an array $ arr = array (); foreach ($ query_str as $ v) {if (preg_match ("/=/", $ v) {$ arr [] = $ v; // standard key name = parameter value, leave it }}$ str = implode ("&", $ arr); // Convert it to the url string parse_str ($ str, $ myArray ); // divide the object into arrays again in the form of $ myArray ['Page'] = $ param; // modify The value of a key name $ myArray ['autor'] = 1000; return substr ($ url, 0, strpos ($ url ,"? "))."? ". Http_build_query ($ myArray); // Complete stitching}
I think it's a little complicated. Which of the following is a simple method ???
Reply to discussion (solution)
Does your asp use php for parsing?
For http://www.abc.com/content/5176.asp? Page = 1 & 5176__2 # p
$ _ GET is an array like this ('page' => 1, '2017 _ 2' => ''), # p won't be used by php
So you can $ _ GET = array_diff ($ _ GET, array (''); GET the array ('page' => 1)
$ _ GET ['author'] = 1000;
Return "" http: // $ _ SERVER [HTTP_HOST]/$ _ SERVER [PHP_SELF]? ". Http_build_query ($ _ GET );
Thank you for your help.