Parse_url
(PHP 4, PHP 5)
Parse_url-parses the URL and returns its components
Description
Array parse_url (string $ url)
This function parses a URL and returns an associated array, which contains various components in the URL.
This function is not used to verify the validity of a given URL, but is used to separate it into the parts listed below. Incomplete URLs are also accepted, and parse_url () tries to parse them correctly as much as possible.
Parameters
Url
URL to be parsed
Return Value
For URLs that are seriously unqualified, parse_url () may return FALSE and issue E_WARNING. Otherwise, an associated array is returned, which consists of (at least one ):
Scheme-such as http
Host
Port
User
Pass
Path
Query-question mark? After
Fragment-after the hash symbol #
Example
Example 2369. parse_url ()
<? Php
$ Url = 'HTTP: // username: password @ hostname/path? Arg = value # anchor ';
Print_r (parse_url ($ url ));
?>
The above example will output:
Array ([scheme] => http [host] => hostname [user] => username [pass] => password [path] =>/path [query] => arg = value [fragment] => anchor)
Note
Note: This function cannot be used for relative URLs.
Note: parse_url () is used to parse a URL instead of a URI. However, there is an exception to PHP backward compatibility. The file: // protocol allows three diagonal lines (file :///...). None of the other protocols can.