PHP | parse_url() Function (original) (raw)

Last Updated : 11 Jul, 2025

The parse_url() function is an inbuilt function in PHP which is used to return the components of a URL by parsing it. It parses an URL and return an associative array which contains its various components.

Syntax:

parse_url( url,url, url,component = -1 )

Parameters: This function accepts two parameters as mentioned above and described below:

Return Values:

Below examples illustrate the use of parse_url() function in PHP:

Example 1:

php `

`

Output:

array(4) { ["scheme"]=> string(4) "http" ["host"]=> string(17) "geeksforgeeks.org" ["path"]=> string(5) "/php/" ["fragment"]=> string(6) "basics" } string(4) "http"

Example 2:

php `

`

Output:

array(3) { ["host"]=> string(21) "www.geeksforgeeks.org" ["path"]=> string(5) "/path" ["query"]=> string(7) "php=PHP" }

Reference: https://www.php.net/manual/en/function.parse-url.php