Verification: a143cc29221c9be0

Php check www in url

Returning an associative array

The parse_url function takes the url as the first argument and an optional component value as the second argument. If the second argument is omitted then it returns the found values as an associative array.

This post is at and getting the associative array of information from it is done like this:

$url = "";
$parts = parse_url($url);

Then doing print_r($parts) will output this:

    [scheme] => http
    [host] =>
    [path] => /php-extract-domain-from-full-url/

If they are present, the array will also contain values for port, user, pass (i.e. password), query (the query string component of the URL) and fragment (the part after the #).

Returning a string

If all you are after is a single component from the array as a single string, pass the second "component" parameter from the following constants: 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.

To just get the domain from this blog post’s URL, do this:

$url = "";
$domain = parse_url($url, PHP_URL_HOST);

PHP Documentation

For more information read the PHP manual page for this function.