Friday 28 March 2014

Get Domain name from the URL using php function

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;
}

print get_domain("http://www.sanajyrao.com"); // outputs 'sanajyrao.com'
print get_domain("http://www.demo.sanajyrao.com"); // outputs 'sanajyrao.com'
print get_domain("http://demo.sanajyrao.com"); // outputs 'sanajyrao.com'
print get_domain("http://sanajyrao.com"); // outputs 'sanajyrao.com'

No comments:

Post a Comment

List OF BANK PAN Numbers

List OF BANK PAN Numbers Bank/Home Loan Providers PAN Number Allahabad Bank AACCA8464F Andhra Bank AABCA7375C Axis Bank...