- assert: documentation ( source)
- array_shift: documentation ( source)
- implode: documentation ( source)
- explode: documentation ( source)
- parse_url: documentation ( source)
<?php
function get_domain($url){
$host = parse_url( $url, PHP_URL_HOST );
$host_parts = explode(".", $host);
if(count($host_parts)>2){
array_shift($host_parts);
}
return implode(".", $host_parts);
}
assert( get_domain("http://eye-talk.org/") == "eye-talk.org" );
assert( get_domain("http://www.eye-talk.org/") == "eye-talk.org" );
assert( get_domain("http://www.eye-talk.org.cc/") == "eye-talk.org.cc" );