Copy link to clipboard
Copied
I usually remove udnesirable special characters that could be entered in a form before submitting to a database with this
<cfset variable = #Replace(variable,"%","", "all")#>
is there a better way I could simply list all of the unwanted values and just replace from that list?
Copy link to clipboard
Copied
The safetext function at cflib.org might help you.
Copy link to clipboard
Copied
I use something like this (below) to not only replace characters, but entire words from strings. I use mostly use this code to replace 'bad words' in moderated forums with 'alternative text'.
Assume you have a field called 'newdata' for your user to fill out, and they type the following:
"In 99% of the studies, someone always badwords ^ the flow of the discussion"
.
Run this against the 'newdata' field before inserting it into the database (or before displaying it on the screen if you want to show it before it is inserted)
<cfset fixeddata = '#ReplaceList(newdata, "%,^,badword"," percent,up,goodword")#'>
The result, if you output the resulting #fixeddata# would read:
"In 99 percent of the studies, somoene always goodwords up the flow of the discussion"
All kinds of possibilities with this.
Hope it helped,
WHeis
Copy link to clipboard
Copied
There's replaceList() or reReplace() which could be used here.
--
Adam