pmpro_getDomainFromURL

Get the "domain" from a URL.

Description

(string) pmpro_getDomainFromURL( (constant) $url = NULL ); 

By domain, we mean the host name, minus any subdomains. So just the domain and TLD.

Returns (string)

The domain.

Parameters (1)

0. $url — Optional. (constant) => NULL
The URL to parse. (generally pass http://hookr.io/functions/site_url" title="site_url" class="code function">site_url() in WP)

Usage

  1. if ( !function_exists( 'pmpro_getDomainFromURL' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/functions.php'; 
  3.  
  4. // The URL to parse. (generally pass site_url() in WP) 
  5. $url = NULL; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = pmpro_getDomainFromURL($url); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/functions.php  
  1. function pmpro_getDomainFromURL($url = NULL) 
  2. $domainparts = parse_url($url); 
  3. $domainparts = explode(".", $domainparts['host']); 
  4. if(count($domainparts) > 1) 
  5. //check for ips 
  6. $isip = true; 
  7. foreach($domainparts as $part) 
  8. if(!is_numeric($part)) 
  9. $isip = false; 
  10. break; 
  11.  
  12. if($isip) 
  13. //ip, e.g. 127.1.1.1 
  14. $domain = implode(".", $domainparts); 
  15. else 
  16. //www.something.com, etc. 
  17. $domain = $domainparts[count($domainparts)-2] . "." . $domainparts[count($domainparts)-1]; 
  18. else 
  19. //localhost or another single word domain 
  20. $domain = $domainparts[0]; 
  21.  
  22. return $domain;