How to quickly obtain required parameters for getting PHP url parameters

Source: Internet
Author: User
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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.