CFLib.org – Common Function Library Project

urlBase64Encode(str)

Last updated August 10, 2007

author

Alan McCollough

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Encodes a string to Base64 format, then urlEncodes the result so that it works when used as part of a URL string. The "Base64 then urlEncode" is necessary to convert any reserved chars such as "+" or "=", which would cause problems if used in a URL string.

Return Values:
Returns a string.

Example:

<cfscript>
myVar = "chars like ? would be bad in a URL";
myencodedvar = urlBase64Encode(myVar);
</cfscript>

<cfoutput>#myencodedvar#</cfoutput>

Parameters:

Name Description Required
str String to format. Yes

Full UDF Source:

/**
 * Encodes a string to base64 format, then urlEncodes the result so that it works when used as part of a URL string.
 * 
 * @param str 	 String to format. (Required)
 * @return Returns a string. 
 * @author Alan McCollough (amccollough@anmc.org) 
 * @version 1, August 10, 2007 
 */
function urlBase64Encode(str){
	
	/* encodes a string to base64 format,
	then urlEncodes the result so that it
	works when used as part of a URL string */
	
	var result = "";
	
	/* convert string to base64 format */
	result = toBase64(str);
	
	/* urlEncode to convert base64 chars that do not work when rendered in a URL 
	Note that this uses the single-argument format to work with earlier versions of CF. */
	result = urlEncodedFormat(result);
	
	return result;
};
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