How to get a domian name from the URL

29 Oct 2019 . 26 views

Hi,

If you want to get the domain name from a url, this snippet might be helpful for you.


$url = 'http://laravel-school.com/posts/understanding-autoload-and-namespace-in-php-57';
$parse = parse_url($url);
echo $parse['host'];  // prints 'laravel-school.com'

Thank you.