Php - How to parse a url using php, How to get domain name from url

How to parse a url using php


parse_url - Parse a URL and return its components.

If we want the domain name or protocol or arguments from the url, we can just simply use parse url function in php.

Parse_url takes url as argument and returns
 scheme - e.g. http
 host
 port
 user
 pass
 path
 query - after the question mark ?
 fragment - after the hashmark #

Example Code:
<?php
$url = 'http://username:password@hostname/path?arg=value#anchor';

print_r(parse_url($url));
?>


The above example will output:
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)

The topic on Php - How to parse a url using php is posted by - Maha

Hope you have enjoyed, Php - How to parse a url using phpThanks for your time

Tech Bluff