Showing posts with label get domain name. Show all posts
Showing posts with label get domain name. Show all posts

Saturday, 13 August 2016

PHP Function to get Domain Name from URL

Use this php function to get domain name form a URL. A simple function which takes a valid url and returns you a domain name.

function getDomainName($sourceurl) {
    if(filter_var($sourceurl, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)===FALSE) {
        return false;
    }
    $url_parts = parse_url($sourceurl);
    return $url_parts['scheme'].'://'.$url_parts['host'];
}