Using ReplaceList to replace bad characters with good characters in a string

This tutorial shows how to replace bad word/characters with good word/characters in a string. Can be used to prevent users submitting bad words. It is easy to make a custom tag of this example. Remember that bad and good character list must be the same length. (Se our custom tags: SafeText is a custom tag that let the user enter HTML code in a text form. The tag will replace all HTML code with their appropriate entity-references.)

Example code:

<cfset text_inn = "Who the fuck is Alice?">
<!--- Define list of "bad" characters --->
<CFSET bad_chars="fuck,sex">
<!--- Define list of "good" characters --->
<CFSET good_chars="f*,-">
<!--- Replace bad words with good words --->
<CFSET safe_content=ReplaceList(text_inn, bad_chars, good_chars)>
<!--- Output original text string --->
<cfoutput>#text_inn#</cfoutput><br>
<!--- Output replaced text string --->
<cfoutput>#safe_content#</cfoutput>

This will give the following output:

Who the fuck is Alice?
Who the f* is Alice?

Advertisement

Playboy

No User Comments.

No User Comments, be the first one to write your comments?

ApplayIT is owned by Scandic Systems LTD [UK] Company No. 5984000. All other trademarks and copyrights are the property of their respective holders.