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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson