On the PHP official website, we can see the replacement of the parse_url () function. The result is similar to that of the parse_url () function, which is implemented using regular expressions.
Original article: http://www.php.net/parse_url#104958
I will not translate it, it can parse URI
Uri is a type of resources available on the web-HTML documents, images, video clips,Program-Is located by an Uniform Resource Identifier ("Uri.
Grouping:
^ ([^ :/? #] + ):)? (// ([^ /? #] *)? ([^? #] *) (\? ([^ #] *)? (#(.*))?
12 3 4 5 6 7 8 9
PHP testing:
<? PHP $ Search = '~ ^ ([^ :/? #] + ):)? (// ([^ /? #] *)? ([^? #] *) (\? ([^ #] *)? (#(.*))?~ I'; $ URL = 'HTTP: // www.php.net/pub/ietf/uri/#related' ; $ URL = Trim ( $ URL ); Preg_match_all ( $ Search , $ URL , $ Rr ); Printf ("<P> output URL data: </P> <PRE> % S </PRE> \ n ", Var_export ( $ Rr , True )); /* The groups are as follows $1 = http: $2 = http $3 = // www.php.net $4 = www.php.net $5 =/pub/IETF/uri/$6 = <undefined> $7 = <undefined> $8 = # related $9 = related */ ?>
Baidu sees another simpleCode:
<?PHP//Obtain the host name from the URLPreg_match("/^ (Http :\/\/)? ([^ \/] +)/I "," http://www.php.net/index.html ",$ Matches);$ Host=$ Matches[2];//Obtain the following two segments from the host namePreg_match("/[^ \. \/] + \. [^ \. \/] + $ /",$ Host,$ Matches);Echo"Domain name is :{$ Matches[0]} \ n";?>
Output after execution:Domain name is: php.net