An alternative to the Parse_url () function seen on the official web site of PHP. The result is similar to the Parse_url () function, and is implemented using a regular. URIs are every resource available on the Web-HTML documents, images, video clips, programs, and so on-positioned by a common resource identifier (Uniform Resource Identifier, referred to as the "URI"). Group objects:
Copy CodeThe code is as follows:
^(([^:/?#]+):)? (//([^/?#]*))? ([^?#]*) (\? ([^#]*))? (#(.*))?
12 3 4
The test code is as follows:
Copy CodeThe code is as follows:
$search = ' ~^ (([^:/?#]+):)? ( //([^/?#]*))? ([^?#]*) (\? ([^#]*))? (# (. *))? ~i ';
$url = ' http://www.jb51.net/pub/ietf/uri/#Gonn ';
$url = Trim ($url);
Preg_match_all ($search, $url, $RR);
printf ("
The output URL data is:
%s
\ n ", Var_export ($RR, TRUE));
/*
The groupings are as follows
$ = http:
$ = http
$ $ =//www.nowamagic.net
$4 = Www.nowamagic.net
$ $ =/pub/ietf/uri/
$6 =
$7 =
$8 = #Gonn
$9 = Gonn
*/
?>
The preceding regular expression can get any part of the URL, and the following code is simple:
Copy the Code code as follows:
Get host name from URL
Preg_match ("/^ (http:\/\/)?" ( [^\/]+)/I "," http://www.jb51.net/index.html ", $matches);
$host = $matches [2];
Get the next two paragraphs from the hostname
Preg_match ("/[^\.\/]+\.[ ^\.\/]+$/", $host, $matches);
echo "Domain name is: {$matches [0]}\n";
?>
http://www.bkjia.com/PHPjc/825116.html www.bkjia.com true http://www.bkjia.com/PHPjc/825116.html techarticle An alternative to the Parse_url () function seen on the official web site of PHP. The result is similar to the Parse_url () function, and is implemented using a regular. URIs are every resource available on the Web-HTML documents, images ...