Get domain name from URL in PHP

1 comment
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.

Code:

<?php
$url = 'http://www.lipku.com/search/label/Tips%20%26%20Tricks';
$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

1 comment :

  1. I was looking for this simple php trick and you have provided it. Thanks for providing such nice simple tips

    ReplyDelete