How to parse an URL in php

How to parse an URL in php

In this blog i will discuss on URL parsing. `parse_url` function parse 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. Use below code to parse a URL

$url = 'https://www.code-learn.com/abc/?slug=test';   //Any URL
print_r(parse_url($url));

Output:below code to parse an URL

Array ( [scheme] => https [host] => www.ecode-learn.com [path] => /abv [query] => slug=test )

Hi, I'm Saurav, the developer behind usingphp. Donate to help me keep usingphp free and maintained.

Please let me know what your thoughts or comments are on this article. If you have any suggestion or found any mistake in this article then please let us know.

Latest Comments

Add your comment