HTML coded text from database do not display properly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pgm16
    New Member
    • Apr 2010
    • 2

    HTML coded text from database do not display properly

    I just added a WYSIWYG editor on my website so my users can format their content any way they want. The editor works fine and is successfully saving the html coded content on the database.

    The problem is when I try to view the content, here's what it shows on the webpage:

    <span style="font-family: Impact;">This is&nbsp; just a test ad only.</span><br><span style="text-decoration: line-through;">This is&nbsp; just a test ad only.</span><br><h3>Th is is&nbsp; just a test ad only.</h3>This is&nbsp; just a test ad only.<br><br><b r><br>

    The html formats do not work.

    The php code to display the content is:

    <?php echo nl2br(preg_repl ace("/\[URL\](.*)\[\/URL\]/iU", "<a href=\"\\1\" target=\"_blank \">\\1</a>$link_append" , $ad['addesc'])); ?>

    Can you please help me correct this code so the html coded text is displayed properly? Or, is there another way to do this?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    Can you show us the code that pulls the HTML from the form, saves it in the database, and finally prints it to the page?

    A basic security feature in PHP is to use htmlentities or htmlspecialchar s to turn HTML code into HTML-readable text, so that the HTML itself is readable instead of becoming a part of the actual HTML page.

    I would guess that somewhere in the code you are using this on your HTML output. You need to locate that in your code and remove it.

    If you fail to find this, you can try using the htmlspecialchar s_decode() function on the outputs string just before printing it. It should revert the changes made by the previously mentioned functions. -- Note that I still recommend you try to locate the other functions and remove them. Using both is redundant; a waste of resources.

    Comment

    • pgm16
      New Member
      • Apr 2010
      • 2

      #3
      Hi Atli,

      Thank you for the advise. I tried replacing the nl2br() with htmlspecialchar s_decode() and it worked perfectly!

      I will try to search for the htmlentities and htmlspecialchar s codes.

      Thanks again...

      Comment

      Working...