CFLib.org – Common Function Library Project

GetSchemeFromURL(this_url)

Last updated February 21, 2002

author

Shawn Seley

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Returns the scheme (ending with "://") for the passed URL. If no scheme is found, then returns an empty string. Works with any protocol that follows a "scheme://x" syntax.

Return Values:
Returns a string.

Example:

<cfoutput>
#GetSchemeFromURL("http://host.com/")#<br>
#GetSchemeFromURL("ftp://@host.com/")#<br>
#GetSchemeFromURL("host.com/")#<br>
#GetSchemeFromURL("telnet://guest:pass@somehost.com:21/")#<br>
</cfoutput>

Parameters:

Name Description Required
this_url URL to parse. Yes

Full UDF Source:

/**
 * Returns the scheme 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 GetSchemeFromURL(this_url) {
	var i = 0;
	
	this_url = trim(this_url);
	
	i = Find("://", this_url, 1);
	if (i LT 1) {
		return ""; // relative url = no scheme   (ex: "../dir1/filename.html" or "/dir1/filename.html")
	} else {
		return Left(this_url, i+2);  // return the "://" and everything to the left of it
	}
}
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