Skip navigation
Currently Being Moderated

Problems saving/ displaying codes

May 16, 2012 3:24 AM

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 :

 

&lt;!--- STRIP OUT ALL HTML ---&gt;

&lt;cfset test = StripToHTML.stripHtml(VARIABLES.text, "all")&gt;

&lt;cfdump var="#test#"&gt;&lt;br/&gt;

 

&lt;!--- STRIP OUT IMG, B, AND EM TAGS ---&gt;

&lt;cfset test1 = StripToHTML.stripHtml(VARIABLES.text, "img,tag,false;b,tag,true;em,content,true")&gt;

&lt;cfdump var="#test1#"&gt;&lt;br/&gt;

 

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.

 
Replies
  • Currently Being Moderated
    May 16, 2012 4:53 AM   in reply to adamaas

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 16, 2012 5:43 AM   in reply to adamaas

    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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points