Im using the following function to cut domain from string:
function get_domain($url)
{
$pieces = parse_url($url);
$domain = isset($pieces['host']) ? $pieces['host'] : '';
if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
return $regs['domain'];
}
return false;
}
I need to cut subdomain + domain how should i change preg_match to get it?
PS i was searching solution but everyone wants to cut only domain without sub.
www.then the problem is still actual.parse_urlprovides the domain name. Please, give some sample input strings and desired result.