Menu Riverview Church

PARSE_URL

Parse a URL and return its components

SYNTAX

parse_url ( string $url [, int $component = -1 ] ) : mixed

PARAMETERS

url

The URL to parse. Invalid characters are replaced by _.

component

Specify one of 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 retrieve just a specific URL component as a string (except when PHP_URL_PORT is given, in which case the return value will be an integer).

RETURN

On seriously malformed URLs, parse_url() may return FALSE. If the component parameter is omitted, an associative array is returned. At least one element will be present within the array. Potential keys within this array are:

KEYS DESCRIPTION
scheme
host
port
user
pass
path
query after the question mark (?)
fragment after the hashtag (#)

If the component parameter is specified, parse_url() returns a string (or an integer, in the case of PHP_URL_PORT) instead of an array. If the requested component doesn't exist within the given URL, NULL will be returned.

EXAMPLES

URL

Array
(
    [scheme] => https
    [host] => hostname
    [port] => 9090
    [user] => username
    [pass] => password
    [path] => /path
    [query] => arg=value
    [fragment] => anchor
)

COMPONENT | PHP_URL_SCHEME

https

COMPONENT | PHP_URL_HOST

hostname

COMPONENT | PHP_URL_PORT

9090

COMPONENT | PHP_URL_USER

username

COMPONENT | PHP_URL_PASS

password

COMPONENT | PHP_URL_PATH

/path

COMPONENT | PHP_URL_QUERY

arg=value

COMPONENT | PHP_URL_FRAGMENT

anchor

PHP