$ 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;
}