air
air

Reputation: 6264

php to display text as html formated stored in database

I have one text saved in MySQL Database

<p> Celebrate with these amazing<br /> offers direct from the  

Now when I print that text using

echo 

I got this output

 <p> Celebrate with these amazing<br /> offers direct from the  

but U want to display that as

Celebrate with these amazing
 offers direct from the  

like HTML print.

when i see in db its stored like bellow

&lt;p&gt;
    Celebrate with these amazing&lt;br /&gt;
    offers from

How to do this?

Upvotes: 0

Views: 11554

Answers (3)

Mick Sear
Mick Sear

Reputation: 1566

If you are outputting to the console (it's not clear from your question what you are trying to output to):

If you look at the PHP strip_tags documentation, you should be able to reach something approximating what you want. https://www.php.net/manual/en/function.strip-tags.php

With strip_tags(), you can allow the
tag to remain and then replace it with "\n" afterwards.

Otherwise, if you are outputting to browser, then other posts on this page have the answer - you must be storing the htmlentities() version of the data in the database.

Upvotes: 0

Nick
Nick

Reputation: 6346

Assuming your database has saved the escaped information like this:

&lt;p&gt;
    Celebrate with these amazing&lt;br /&gt;
    offers from

Then you could just use PHP's html_entity_decode function to output that block of HTML.

Upvotes: 7

Coder
Coder

Reputation: 896

maybe this could help you http://php.about.com/od/phpwithmysql/qt/php_in_mysql.htm

Upvotes: 0

Related Questions