PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      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. Warning: Undefined array key "url" in /code/templates_c/1147dd74356edff87ad358bc1914c2fbf5fa2dbf_0.file.parse_url.tpl.php on line 42 Warning: Attempt to read property "value" on null in /code/templates_c/1147dd74356edff87ad358bc1914c2fbf5fa2dbf_0.file.parse_url.tpl.php on line 42 Warning: Undefined array key "component" in /code/templates_c/1147dd74356edff87ad358bc1914c2fbf5fa2dbf_0.file.parse_url.tpl.php on line 42 Warning: Attempt to read property "value" on null in /code/templates_c/1147dd74356edff87ad358bc1914c2fbf5fa2dbf_0.file.parse_url.tpl.php on line 42

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.