CFLib.org – Common Function Library Project

GetPortFromURL(this_url)

Last updated February 21, 2002

author

Shawn Seley

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Returns the port number for the supplied URL. If no port number is found, then returns an empty string. Works with any protocol that follows a "x.x:PortNumber" syntax where PortNumber = one or more digits. Supporting protocols include http, ftp, telnet, and others. Note, this function will return an empty string for any implied port numbers (containing a ":" but no digits afterwards).

Return Values:
Returns a string.

Example:

<cfoutput>
#GetPortFromURL("telnet://guest:pass@somehost.com:21/")#<br>
#GetPortFromURL("somehost.com:80")#<br>
#GetPortFromURL("somehost.com:")#<br>
#GetPortFromURL("http://somehost.com:8000")#<br>
</cfoutput>

Parameters:

Name Description Required
this_url URL to parse. Yes

Full UDF Source:

/**
 * Returns the port number from a specified URL.
 * 
 * @param this_url 	 URL to parse. 
 * @return Returns a string. 
 * @author Shawn Seley (shawnse@aol.com) 
 * @version 1, February 21, 2002 
 */
function GetPortFromURL(this_url) {
	var re_found_struct = "";
	
	this_url = trim(this_url);
	
	re_found_struct = REFind("[^./].[^./:]+(:[[:digit:]]+)", this_url, 1, "True");

	if (re_found_struct.pos[1] GT 0) {
		return Mid(this_url, re_found_struct.pos[2]+1, re_found_struct.len[2]-1);
	} else {
		return "";
	}
}
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