Skip to main content
adamaas
Known Participant
May 16, 2012
Question

Problems saving/ displaying codes

  • May 16, 2012
  • 2 replies
  • 846 views

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.

    This topic has been closed for replies.

    2 replies

    Inspiring
    May 16, 2012

    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

    adamaas
    adamaasAuthor
    Known Participant
    May 17, 2012

    htmlEditFormat() don't do the trick and am using coldfusion 9 so can't use the encodeforhtml.

    Inspiring
    May 16, 2012

    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.

    adamaas
    adamaasAuthor
    Known Participant
    May 17, 2012

    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 &lt;b&gt;Hello&lt;/b&gt;

    I have already do a rereplace function to replace the &lt; and &gt; 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 ?