PHP parseURL a useful function
parse_url-resolves the URL and returns its constituent parts. Description Array parse_url (string $url)
This function resolves a URL and returns an associative array containing the various components that appear in the URL.
This function is not used to verify the legality of a given URL, but to decompose it into the sections listed below. An incomplete URL is also accepted, and Parse_url () tries to parse it as correctly as possible. return value
For severely unqualified URLs, parse_url () may return FALSE and emit e_warning. Otherwise, an associative array is returned with a component (at least one): scheme-such as HTTP host port user Pass path query-at the question mark? After fragment-after the hash symbol #
Examples are as follows:
$url = "http://www.electrictoolbox.com/php-extract-domain-from-full-url/";
$parts = Parse_url ($url);
Output:
Array
(
[scheme] => HTTP
[host] => www.electrictoolbox.com
[path] =>/ php-extract-domain-from-full-url/
Another example:
$url = ' Http://username:password@hostname/path?arg=value#anchor ';
Print_r (Parse_url ($url));
Echo Parse_url ($url, php_url_path);
Output:
Array
(
[scheme] => HTTP
[host] => hostname
[user] => username
[Pass] = > Password
[path] =>/path
[query] => arg=value
[fragment] => anchor
As you can see, it's easy to break down the various parts of a URL, so it's easy to get the specified parts out, like
Echo Parse_url ($url, Php_url_path);
In the second argument, you set the following parameters:
Php_url