[thelist] CF -- scrubbing special characters

Frank frank at loofahcom.com
Mon Sep 9 23:42:20 CDT 2002


On Monday, September 09, 2002, 5:04:32 PM, you said:

r> i've tried searching the archives but got nowhere fast

r> wasn't there a thread recently about how to replace special characters in a
r> form field using coldfusion?

r> any coldfusion suggestions welcome

This is an old standby, that should illustrate the
principle. I'm sure most would choose to set it to an array,
but at the time of writing, this worked for me. Replace with
whatever you choose, I needed HTML entities at the time.

Watch out for the most vicious wrap.


<!--- Keep a copy of the original string, to compare in debugging test. --->
<cfset OriginalString="#StringToConvert#">

<!--- Define the list of entities to be converted to ASCII --->
<cfset Entities="&amp;,&lt;,&gt;,&quot;,&AElig;,&Aacute;,&Acirc;
&Agrave;,&Aring;,&Atilde;,&Auml;,&Ccedil;,&ETH;,&Eacute;,&Ecirc;
&Egrave;,&Euml;,&Iacute;,&Icirc;,&Igrave;,&Iuml;,&Ntilde;,&Oacute;,
&Ocirc;,&Ograve;,&Oslash;,&Otilde;,&Ouml;,&THORN;,&Uacute;,&Ucirc;,
&Ugrave;,&Uuml;,&Yacute;,&aacute;,&acirc;,&aelig;,&agrave;,&aring;,
&atilde;,&auml;,&ccedil;,&eacute;,&ecirc;,&egrave;,&eth;,&euml;,
&iacute;,&icirc;,&igrave;,&iuml;,&ntilde;,&oacute;,&ocirc;,&ograve;,
&oslash;,&otilde;,&ouml;,&szlig;,&thorn;,&uacute;,&ucirc;,&ugrave;,
&uuml;,&yacute;,&yuml;,&iexcl;,&pound;,&curren;,&yen;,&brvbar;,
&sect;,&uml;,&copy;,&ordf;,&laquo;,&not;,&shy;,&reg;,&macr;,&deg;,
&plusmn;,&sup2;,&sup3;,&acute;&micro;,&para;,&middot;,&cedil;,
&sup1;,&ordm;,&raquo;,&frac14;,&frac12;,&frac34;,&iquest;,&times;,
&divide;,&cent;">

<!--- Define the list of ASCII chars to replace the entities. --->
<cfset ASCIIChars="&,<,>,"",Æ,Á,Â,À,Å,Ã,Ä,Ç,Ð,É,Ê,È,Ë,Í,Î,Ì,Ï,Ñ,Ó,
Ô,Ò,Ø,Õ,Ö,Þ,Ú,Û,Ù,Ü,Ý,á,â,æ,à,å,ã,ä,ç,éê,è,ð,ë,í,î,ì,ï,ñ,ó,ô,ò,ø,õ,
ö,ß,þ,ú,û,ù,ü,ý,ÿ,¡,£,¤,¥,¦,§,¨,©,ª,«,¬,­,®,¯,°,±,²,³,´,µ,¶,·,¸,¹,º,
\»,¼,½,¾,¿,×,÷,¢">

<!--- Replace the entities with the ASCII --->
<cfset StringConverted="#ReplaceList(StringToConvert, Entities, ASCIIChars)#">




More information about the thelist mailing list