How can I quickly obtain the required parameter www. abc. comcontent5176.asp? Page1 & amp; 5176__2 # p current url is this link. now I need to generate a link www. abc. comcontent5176.asp? How to quickly complete page1 & amp; author10000 ?? My practice is to get the url parameters in PHP. how can I get the required parameters quickly?
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, excluding #
$ Query_str = explode ("&", $ query_str); // cut it into an array
$ Arr = array ();
Foreach ($ query_str as $ v ){
If (preg_match ("/=/", $ v )){
$ Arr [] = $ v; // The standard key name = parameter value is left
}
}
$ Str = implode ("&", $ arr); // Convert it to a url string
Parse_str ($ str, $ myArray); // split it into arrays again
$ MyArray ['Page'] = $ param; // modify the value of a key name.
$ MyArray ['author'] = 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 ???
------ 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 );