regex for getting domain from url or other methods?
how can I test how fast a regex is compared to others?
I want to be able to get the domain from any url.
Code:
<?php
function get_hostname($url) {
if (preg_match('#([0-9a-z.-]+)#i',preg_replace('#^(?:(?:\w+):(?:\\?)?)#i','',$url),$matches)) return $matches[1];
}
$hostname = 'http://www2.example.com:80/test/evil--kj12/cb_2/1.html';
echo $hostname . '<br/> '. get_hostname($hostname);
?>
this is what i got so far, works just curious any others got any other ways
|