How to quickly obtain the required url parameters

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

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.