How to get a domain name from the URL

How to get a domain name from the URL

Posted on:October 29, 2019 at 10:00 AM

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.