ColdFusion UDF Library - htmlEncode
December 16th, 2008
«« Back to ColdFusion Library
Category:
STRINGS
Description:
Encodes HTML (similar to: htmlEditFormat)
Parameters:
Returns:
(String) encoded HTML
Requires:
Sample Use:
encodeMe = htmlEncode("&foobar");
Copy to Clipboard
Category:
STRINGS
Description:
Encodes HTML (similar to: htmlEditFormat)
Parameters:
- str (String, required)
The string containing the HTML you wish to encode.
Returns:
(String) encoded HTML
Requires:
Sample Use:
encodeMe = htmlEncode("&foobar");
Copy to Clipboard
function htmlEncode(str){
var loop = 0;
var strLen = len(str);
var ascii = 0;
var hex = "";
for (loop = 1; loop lte len(str); loop = incrementValue(loop)){
ascii = asc(mid(str,loop,1));
hex = formatBaseN(ascii,16);
if (len(hex) lt 4)hex = "00"&hex;
str = insert("#x#hex#;",str,loop);
str = removeChars(str,loop,1);
loop = loop+7;
};
return str;
};
// http://www.programmers.org/index.php/coldfusion-udf-library/?ckey=75&function=htmlEncode



