Get Domain Name from URL in PHP

Get Domain Name from URL in PHP
Get Domain Name from URL in PHP

Recently I need to get the domain name from the URL. This is a small task but it is very useful stuff. In this short article, We’ll provide you simple and easy code to get the domain name from URL in PHP.

First you need to parse URL using parse_url(). you can get the array from parse URL. Now, you can get the specific host from the array using $parse[‘host’].

In this example, you’ll be able to get only the domain name from your current URL.