Reputation: 684
I have some values in my database which a column named description
contains HTML CODE ex. (<p> </p><div class="col-xs-8">..
).
I get the database rows and try to show it in the page, all the columns displays normal (as it is plain text) BUT when I echo
the variable that contains description
value it doesn't turn the code into "page", it only shows the code.
Where is the problem? Shouldn't it consider as code as well and add it to the page?
CODE:
<div class="info">
<div class="info-space" style="width: 800px;"></div>
<?php
echo $pro_desc;
?>
</div>
</div>
Upvotes: 1
Views: 142
Reputation: 1995
Your $pro_desc
looks like this:
string '<p>&nbsp;</p><div class="col-xs-8"...length(25000)
In order to display it correctly, you need to convert it to HTML format, for example <p>
to <p>
and so on. Try this:
echo "<p>".html_entity_decode($pro_desc)."</p>";
More info: http://php.net/manual/en/function.html-entity-decode.php
Upvotes: 1
Reputation: 1308
It's important that you try this code:
htmlspecialchars($_POST['description'] , ENT_QUOTES);
before you save your description in the database and when you need to fetch this field use :
htmlspecialchars_decode($data['description']);
You can read more here. http://php.net/htmlspecialchars
Upvotes: 0