Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert database description string to html code in PHP

Tags:

html

php

I am creating a laravel web application for a client which allows them to store information into a database.

So i am using a WYSIWYG editor to allow the users to enter data with bullet points, bold text and underlines ect...

Now when i save the description to my database it looks like this.

test test<div><br></div><div><br></div><div><b>egergererh<i>this is a bullet</i><u><i>hello</i>egerg</u>ewg</b>ewg</div><div><br></div><div><ul><li>wegwe</li></ul><ol><li>ewg</li></ol></div>

So when the user previews the page with the description i want it to show with the html marked up. But instead I find a string of html that looks like this on my page.(not the real thing for an example)

test test <div><br/><div></div></div>

How do i retrieve the description from the database and present it to the page as html?

i have tried

htmlspecialchars_decode()

but this doesnt do anything.

like image 399
Matthew Smart Avatar asked Aug 11 '26 00:08

Matthew Smart


1 Answers

try it with:

<?php
$str = 'test test&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;egergererh&lt;i&gt;this is a bullet&lt;/i&gt;&lt;u&gt;&lt;i&gt;hello&lt;/i&gt;egerg&lt;/u&gt;ewg&lt;/b&gt;ewg&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;wegwe&lt;/li&gt;&lt;/ul&gt;&lt;ol&gt;&lt;li&gt;ewg&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;';

echo html_entity_decode($str);
like image 87
Chetan Ameta Avatar answered Aug 13 '26 12:08

Chetan Ameta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!