Get domain name from URL in PHP

By | August 8, 2020

Hello guys, today I am going to tell you a small tip about 'How to get a domain name from URL in PHP'. Getting domain from url is not a big task and it can be parsed in maximum two or three lines of code. Here I am going to demonstrate you a simple way to parse domain name from URL.

By using parse_url() function:
parse_url() function parse a URL and returns an array that contains various elements of the URL that are present.


$url = '';
$domain = parse_url($url,PHP_URL_HOST);
echo $domain;

I hope this small tutorial will help you a lot in your web development.

Related Tutorial: Get domain name from email using PHP

Leave a Reply

Your email address will not be published. Required fields are marked *