public static function getDomainName(string $url): string
    {
        if (isset(self::$cached_url_domains[$url])) {
            return self::$cached_url_domains[$url];
        }

        $parsed_url = parse_url(strtolower($url));
        $host = $parsed_url['host'] ?? '';

        /// Remove www. part
        if (0 === strpos($host, 'www.')) {
            $host = substr($host, 4);
        }

        // Get last part (zone)
        $parts = array_reverse(explode('.', $host));

        if (!$parts || !self::zoneExists($parts[0])) {
            return '';
        }

        if(count($parts)==1){
            $domain = $parts[0];
        }else {
            $zone = '.' . $parts[0];

            // Save parsed url and found zone
            $domain = substr($host, 0, -strlen($zone));
        }

        return self::$cached_url_domains[$url] = $domain;
    }
public static function getDomainName(string $url): string
    {
        if (isset(self::$cached_url_domains[$url])) {
            return self::$cached_url_domains[$url];
        }

        $parsed_url = parse_url(strtolower($url));
        $host = $parsed_url['host'] ?? '';

        /// Remove www. part
        if (0 === strpos($host, 'www.')) {
            $host = substr($host, 4);
        }

        // Get last part (zone)
        $parts = array_reverse(explode('.', $host));

        if (!$parts || !self::zoneExists($parts[0])) {
            return '';
        }

        if(count($parts)==1){
            $domain = $parts[0];
        }else {
            $zone = '.' . $parts[0];

            // Save parsed url and found zone
            $domain = substr($host, 0, -strlen($zone));
        }

        return self::$cached_url_domains[$url] = $domain;
    }
public static function getDomainName ( string $ url ) : string { if ( isset ( self :: $ cached_url_domains [ $ url ] ) ) { return self :: $ cached_url_domains [ $ url ] ; } $ parsed_url = parse_url ( strtolower ( $ url ) ) ; $ host = $ parsed_url [ 'host' ] ?? '' ; /// Remove www. part if ( 0 === strpos ( $ host , 'www.' ) ) { $ host = substr ( $ host , 4 ) ; } // Get last part (zone) $ parts = array_reverse ( explode ( '.' , $ host ) ) ; if ( ! $ parts || ! self :: zoneExists ( $ parts [ 0 ] ) ) { return '' ; } if ( count ( $ parts ) == 1 ) { $ domain = $ parts [ 0 ] ; } else { $ zone = '.' . $ parts [ 0 ] ; // Save parsed url and found zone $ domain = substr ( $ host , 0 , - strlen ( $ zone ) ) ; } return self :: $ cached_url_domains [ $ url ] = $ domain ; }
Get domain name by full URL address

@param string $url

@return string
Get domain name by full URL address