PHPize Online / SQLize Online
A A A

Share   Donate   Blog   Popular

parse_url

Tags: PHP 5.x PHP 7.x PHP 8.x

parse_url — Parse a URL and return its components.

Description

parse_url(
    string $url,
int $component = -1
): mixed
This function parses a URL and returns an associative array containing any of the various components of the URL that are present. The values of the array elements are not URL decoded.
This function is not meant to validate the given URL, it only breaks it up into the above listed parts. Partial and invalid URLs are also accepted, parse_url() tries its best to parse them correctly.

Parameters

string
The URL to parse.
int
The specific component to return. Use one of 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

Return Values

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.