CFLib.org – Common Function Library Project

getHostAndTLD(domain)

Last updated October 29, 2010

author

Patrick Heppler

Version: 2 | Requires: CF5 | Library: NetLib

Description:
Returns the Hostname and TLD from a FQDN.

Return Values:
Returns a struct with hostname and toplevel domain.

Example:

<cfset domain="example.co.uk">
<cfdump var="#GetHostAndTLD(domain)#">

Returns a struct.
result.hostname: example
result.tld: co.uk

Parameters:

Name Description Required
domain Full Qualified Domain Name. Yes

Full UDF Source:

/**
 * Get the TLD and Hostname from FQDN.
 * v2 by Ray - just added a var scope
 * 
 * @param domain      Full Qualified Domain Name. (Required)
 * @return Returns a struct with hostname and toplevel domain. 
 * @author Patrick Heppler (p.heppler@fusionality.de) 
 * @version 2, October 29, 2010 
 */
function getHostAndTLD(domain) {
var result=structnew();
if (len(domain) lte 0) return false;
       result.hostname=listfirst(domain,".");
       if(listlen(domain,".") gt 2){
               result.tld=listgetat(domain,2,".")&"."&listgetat(domain,3,".");
               }
       else{
               result.tld=listlast(domain,".");
               }
       return result;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson