CFLib.org – Common Function Library Project

getHostFromURLJava([url])

Last updated June 05, 2008

author

Todd Sharp

Version: 1 | Requires: CF5 | Library: UtilityLib

Description:
Uses Java to extract the host name from a URL. Different from getHostFromURL (http://www.cflib.org/udf.cfm?id=494) since this UDF uses Java to extract the host name and getHostFromURL uses regex.

Return Values:
Returns a string containing the host name.

Example:

<cfset greatBlog = "http://cfsilence.com/client/blog" />
<cfset host = getHostFromURL(greatBlog) />
<cfoutput>#host#</cfoutput>
<!--- outputs 'cfsilence.com' --->

Parameters:

Name Description Required
url the url from which you want to extract the host name No

Full UDF Source:

<!---
 Extracts the host name from a URL.
 
 @param url      the url from which you want to extract the host name (Optional)
 @return Returns a string containing the host name. 
 @author Todd Sharp (todd@cfsilence.com) 
 @version 1, June 5, 2008 
--->
<cffunction name="getHostFromURL" access="public" output="false" returntype="string">
    <cfargument name="url" required="false" default="" />
    <cfset var jURL = "" />
    <cfif len(arguments.url)>
        <cfset jURL = createObject("java", "java.net.URL").init(arguments.url) />
        <cfreturn jURL.getHost() />
    <cfelse>
        <cfreturn ""/>
    </cfif>
</cffunction>

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