0

I have stored user description from a <textarea> plugin. The description stores as follow in my database

&lt;b&gt;Brian&lt;/b&gt; is an amazing photographer! We used Brian for our engagement and wedding photos and he

But when I am printing that code using PHP as follow:

<div style="overflow: auto;width: 100%" align="left">
    <?=$getlistingdata->ldesctiption?>
</div>

Then the code is printed as below: enter image description here It does not Apply Html Code . instead the code is printing ?

How can I apply html ?

Tanya Rix
  • 69
  • 10
Mad Coder
  • 117
  • 14
  • using `<` instead of `<` is for this exact purpose, that the character shows and doesn't get parsed as HTML tag beginning. It seems these characters were encoded before sent to database, is there an option in the plugin to preserve html characters? – Kaddath May 04 '18 at 08:57
  • Storing HTML code in database is a stupid idea – Alexxus May 04 '18 at 09:00
  • 2
    @Alexxus be cautious calling things stupid, as you might do them yourself one day :) what's your recommendations for a user text formatting like a ``? Create a special placeholder for them and decode/encode each time you store to database (a bit overkill?), or discard any user text formatting because you find a `` in database stupid? – Kaddath May 04 '18 at 10:37
  • @Kaddath: There are many ways to avoid that. And no, it's not an overkill. There are a lot markdown parser out there for instance. Just search them on [packagist](https://packagist.org/?q=markdown%20parser&p=0), download and use them! – Alexxus May 07 '18 at 05:08

1 Answers1

0

You either need to store the HTML code unescaped, or unescape it before printing it.

Either way, you can unescape it using the htmlspecialchars_decode function. So, something like this should work:

<div style="overflow: auto;width: 100%" align="left">
    <?= htmlspecialchars_decode($getlistingdata->ldesctiption) ?>
</div>
Tudor
  • 1,798
  • 2
  • 12
  • 21