- print_r: documentation ( source)
- parse_url: documentation ( source)
- preg_replace: documentation ( source)
- strtolower: documentation ( source)
<?php
function domainGetFromURL($url, $strip_www = true) {
echo print_r(parse_url($url), true);
if (!$p = @parse_url($url)) {
return '';
}
if (strlen($p['host']) == 0) {
return '';
}
if ($strip_www) {
$domain = preg_replace('#^www\.(www\.)*#', '', strtolower($p['host']));
} else {
$domain = strtolower($p['host']);
}
return $domain;
}
$url = 'domain.ru';
echo domainGetFromURL($url, false);