Copy link to clipboard
Copied
Hello,
I want to save html codes or any language code in my database.
For instance, am saving the text below in the database :
<!--- STRIP OUT ALL HTML --->
<cfset test = StripToHTML.stripHtml(VARIABLES.text, "all")>
<cfdump var="#test#"><br/>
<!--- STRIP OUT IMG, B, AND EM TAGS --->
<cfset test1 = StripToHTML.stripHtml(VARIABLES.text, "img,tag,false;b,tag,true;em,content,true")>
<cfdump var="#test1#"><br/>
When it has been saved in the database, it's like follows :
<!--- STRIP OUT ALL HTML --->
<cfset test = StripToHTML.stripHtml(VARIABLES.text, "all")>
<cfdump var="#test#"><br/>
<!--- STRIP OUT IMG, B, AND EM TAGS --->
<cfset test1 = StripToHTML.stripHtml(VARIABLES.text, "img,tag,false;b,tag,true;em,content,true")>
<cfdump var="#test1#"><br/>
And when I am displaying it on a page, it displayed as above.
Someone can tell me how to save the codes in the correct format in the database and how to make them display correctly ?
I am using MSSQL 2008 for the database.
Copy link to clipboard
Copied
Go to cflib.org and look for a function called safetext. It will preserve benign tags and strip out dangerous ones.
Then, store the html exactly as you receive it. Use safetext when you display it.
Copy link to clipboard
Copied
well I have used the function safetext but unfortunately its not good.
I have test it with the test below :
Hello V/s <b>Hello</b>
and the result after using safetext qive me the result :
Hello V/s <b>Hello</b>
I have already do a rereplace function to replace the < and > with <> but this would appear like :
Hello V/s Hello
Instead of showing the tag b , it execute the html tag.
I don't know how to make any codes appear on a page.
Could anyone please help me ?
Copy link to clipboard
Copied
So you don't want to strip it out, you want to escape it?
Would htmlEditFormat() do the trick? Or if you're on CF10 (which, admittedly, is doubtful ;-), encodeForHtml()?
--
Adam
Copy link to clipboard
Copied
htmlEditFormat() don't do the trick and am using coldfusion 9 so can't use the encodeforhtml.