getHostname() public static method

public static getHostname ( string $url ) : string | false
$url string
return string | false
 public function testHostnames()
 {
     foreach ($this->hostnames as $expectedHost => $samples) {
         foreach ($samples as $url) {
             $parsedHostname = Domainparser::getHostname($url);
             $this->assertNotFalse($parsedHostname, 'Parsed hostname for ' . $url . ' should not be false');
             $this->assertEquals($expectedHost, $parsedHostname, 'Expected hostname ' . $expectedHost . ', got ' . $parsedHostname . ' instead.');
         }
     }
 }
Beispiel #2
0
function clean($url, $list = [])
{
    // only hostnames & path
    $url = Domainparser::getHostname($url) . Domainparser::getPath($url);
    // delete redundant subdomains
    $root = Domainparser::getRootDomain($url);
    if (!empty($list) && $root !== Domainparser::getHostname($url) && in_array($root, $list)) {
        $url = '';
    }
    // trailing /
    $url = trim($url, '/');
    // lower case
    $url = strtolower($url);
    $url = trim($url);
    $punicode = new \TrueBV\Punycode();
    $url = iconv("UTF-8", "ISO-8859-1", $punicode->encode($url));
    return $url;
}