CFLib.org – Common Function Library Project

getHostFromURLJava([url])

Last updated June 5, 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>
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