CFLib.org – Common Function Library Project

getHostAndTLD(domain)

Last updated October 29, 2010

Version: 2 | Requires: ColdFusion 5 | Library: NetLib

 
Rated 5 time(s). Average Rating: 2.4

Description:
Returns the Hostname and TLD from a FQDN.

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

Example:

view plain print about
<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:

view plain print about
<cfscript>
/**
 * 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;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Dave Anderson Dave Anderson added
iniToStruct
20 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
20 day(s) ago

Richard Richard added
dice
22 day(s) ago

Isaac Dealey Isaac Dealey added
getRelative
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 22 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson