- $ 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 is how to use the PHP function parse_url:
- < ?php
- $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, the PHP function parse_url can easily break down all parts of a URL. It is also easy to take the specified part, as shown in figure
Echo parse_url ($ url, PHP_URL_PATH); in the second parameter, set the following parameter:
PHP_URL_SCHEME, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_USER, PHP_URL_PASS, PHP_URL_PATH, PHP_URL_QUERY or PHP_URL_FRAGMENT.