Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render html tags from mysql database in PHP?

Tags:

html

php

I am storing html tags like <ul><li>....</li></ul>, etc in the table. I want to retrieve these values as html content. When I retrieve this data I want to show it as HTML content, that is, it should show bullets instead of <ul><li>....</li></ul>.

Code which I am trying:

<?php echo stripslashes($row3['description'])?>

I have even tried htmlentities(), html_entity_decode() but, none have worked.

like image 836
Tejas Navghane Avatar asked Feb 05 '16 06:02

Tejas Navghane


People also ask

How do I display HTML tags as plain text in laravel?

Display HTML In Laravel Blade Views By default you would use the following syntax {{ $some_variable }} to echo out the content of a specific variable in Blade. By default the {{ }} escapes the HTML tags. In the first case, you can see how the HTML elements were escaped, and in the second case where we use {!! !!}


3 Answers

You can Use htmlspecialchars_decode function as below :

echo htmlspecialchars_decode(stripslashes($row3['description'])); 

Instead of

 echo stripslashes($row3['description']);

You can know more about function here : http://php.net/manual/en/function.htmlspecialchars-decode.php

like image 104
Butani Vijay Avatar answered Oct 06 '22 21:10

Butani Vijay


for laravel users just do this

{!! $my_db_ish['my_row'] !!}

instead of

{{ $my_db_ish['my_row'] }}
like image 24
The Billionaire Guy Avatar answered Oct 06 '22 19:10

The Billionaire Guy


Use htmlspecialchars_decode.

$str = "<ul><li></li></ul>";

echo htmlspecialchars_decode($str);

Hope it will help you :)

like image 43
Ravi Avatar answered Oct 06 '22 20:10

Ravi