stringToAscii(str)
Last updated June 17, 2010
Version: 1 | Requires: CF6 | Library: CFMLLib
Description:
Pass me a string and I'll convert it into HTML-friendly ASCII characters.
Return Values:
Returns a string.
Example:
<cfset str = "I’ve ¼ got © some ™ funky € characters ? to ? convert ¥ into ® ASCII ¶ eh?" />
<cfdump var="#stringToAscii(str)#" />
Parameters:
Name | Description | Required |
---|---|---|
str | String to parse. | Yes |
Full UDF Source:
/**
* I convert a string to ASCII characters.
*
* @param str String to parse. (Required)
* @return Returns a string.
* @author Stephen Withington (steve@stephenwithington.com)
* @version 1, June 17, 2010
*/
function stringToAscii(str) {
var local = StructNew();
local.oldStr = '';
local.newStr = '';
if ( StructKeyExists(arguments, 'str') and IsSimpleValue(arguments.str) ) {
local.oldStr = arguments.str;
for ( local.i=1; local.i lte Len(arguments.str); local.i++ ) {
local.newStr = local.newStr & '&##' & Asc(Left(local.oldStr,1)) & ';';
local.oldStr = RemoveChars(local.oldStr,1,1);
};
};
return local.newStr;
};
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