parse_url
(PHP 4, PHP 5)
parse_url — Parse a URL and return its components
Description
array parse_url ( string $url )
This function parses a URL and returns an associative array containing the various components that appear in the URL.
This function is not used to verify the validity of the given URL, but to break it down into the parts listed below. Incomplete URLs are also accepted and parse_url() will try to parse them as correctly as possible.
Parameters
url
The URL to be parsed
Return value
For severely unqualified URLs, parse_url() may return FALSE and issue E_WARNING. Otherwise, an associative array is returned whose components are (at least one):
scheme - such as http
host
port
user
pass
path
query - after the question mark?
fragment - after the hash symbol #
Example
Example 2369. parse_url() Example
$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)
Comments
Note: This function cannot be used for relative URLs.
Note: parse_url() is specifically used to parse URLs rather than URIs. However, there is an exception to comply with PHP backward compatibility needs, and three slashes are allowed for the file:// protocol (file:///...). No other agreement can do this.