CFLib.org – Common Function Library Project

GetSchemeFromURL(this_url)

Last updated February 22, 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
    }
}

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