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.
<?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