Get domain name from url in php

Extract domain name from the url in php can be done with following snippet

function get_domain_from_url($url)
{
  $pieces = parse_url($url);
  $domain = isset($pieces['host']) ? $pieces['host'] : $pieces['path'];
  if (preg_match('/(?P[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
    return $regs['domain'];
  }
  return false;
}

print get_domain_from_url("https://minitick.in");
// output of above snippet will be given as 'minitick.in'

php,domain