'output html from database literally

I have HTML tags formatted in the database (< becomes &lt; and so on).

The problem I'm having is the HTML tags are being outputted literally; instead of <b>Text</b> making text bold, it's being displayed as &lt;b&gt;

Does anybody know why this is? Or how to fix it please?

The output on the website: the website

HTML code in the DB: partial image of the data in the DB.



Solution 1:[1]

I think you intended to replace all < with &lt; and so on while storing the HTML in database. But I find that in your db, the <script ... tag looks like &amp;lt;script .... Try replacing it with something like &lt;script .... Also make sure that the correct MIME type is set. For an HTML page, use :

header('Content-type: text/html');

Solution 2:[2]

Rather than maybe decoding, make sure you aren't double encoding it. If you have encoded data in the database and then you encode it again when printing it out, it should be rendered as < etc.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vivek
Solution 2 Masse