Php quick way to get url parameters

Source: Internet
Author: User

 

$ Url = "http://www.111cn.net.net/welcome ";

$ Parts = parse_url ($ url );

Print_r ($ parts );

/*
Array
(
[Scheme] => http
[Host] => www.111cn.net.net
[Path] =>/welcome/
)

In this way, we have a lot of space to get the content of each part of the url.

As you can see, it is easy to break down all parts of a url. It is also easy to take the specified part, for example:

View sourceprint? 1 echo parse_url ($ url, php_url_path );

In the second parameter, set the following parameters: php_url_scheme, php_url_host, php_url_port, php_url_user, php_url_pass, php_url_path, php_url_query or php_url_fragment

*/

Look at a complicated function.

Function parseurl ($ url ){
$ R = "^ (? :(? P <scheme> w + )://)? ";
$ R. = "(? :(? P <login> w + ):(? P <pass> w + )@)? ";
$ R. = "(? P $ R. = "(? ::(? P <port> d + ))? ";
$ R. = "(? P <path> [w/] */(? P <file> w + (? :. W + )?)?)? ";
$ R. = "(? :? (? P <arg> [w = &] + ))? ";
$ R. = "(? :#(? P <anchor> w + ))? ";
$ R = "! $ R! "; // Delimiters
      
Preg_match ($ r, $ url, $ out );
      
Return $ out;
    }

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.