You are here

function _emimage_custom_url_get_domain_helper in Embedded Media Field 6.3

Same name and namespace in other branches
  1. 6 contrib/emimage/providers/custom_url.inc \_emimage_custom_url_get_domain_helper()

Function carves out the domain name out of any URL, including URLs with sub- domains and additional extensions.

Parameters

$url An object of type String with a URL as its value.:

Return value

An object of type String with the carved domain name as its value.

2 calls to _emimage_custom_url_get_domain_helper()
_emimage_custom_url_get_domain_server in contrib/emimage/providers/custom_url.inc
_emimage_custom_url_scrape_image_title in contrib/emimage/providers/custom_url.inc
Function uses a helper function _get_domain_helper to get the name of the domain where the image is hosted.

File

contrib/emimage/providers/custom_url.inc, line 192

Code

function _emimage_custom_url_get_domain_helper($url) {
  $url = strtolower($url);
  $slds = '\\.co\\.uk|\\.me\\.uk|\\.net\\.uk|\\.org\\.uk|\\.sch\\.uk|
    \\.ac\\.uk|\\.gov\\.uk|\\.nhs\\.uk|\\.police\\.uk|
    \\.mod\\.uk|\\.asn\\.au|\\.com\\.au|\\.net\\.au|\\.id\\.au|
    \\.org\\.au|\\.edu\\.au|\\.gov\\.au|\\.csiro\\.au';
  preg_match("/^(http:\\/\\/|https:\\/\\/)([^\\/]+)/i", $url, $matches);
  $host = $matches[2];
  if (preg_match("/{$slds}\$/", $host, $matches)) {
    preg_match("/[^\\.\\/]+\\.[^\\.\\/]+\\.[^\\.\\/]+\$/", $host, $matches);
  }
  else {
    preg_match("/[^\\.\\/]+\\.[^\\.\\/]+\$/", $host, $matches);
  }
  return "{$matches[0]}";
}