use string html text to html
The question is this, i have some text that i bring from the DB.
The info is recorded as HTML.
When i bring that info, it comes as "<b>hello world</b>"
i mean, it comes all the html as string, and i want to use that string as html. I think there is a function in php for this, but i dont find.
example:
i have "<b>hello world&开发者_如何学JAVAlt;/b>"
and need to be hello world
You can use:
echo htmlspecialchars_decode($var);
I think you use htmlspecialchar()
when you insert to database
See the functions
- htmlentitites() (to make Hello =>
<b>Hello</b>
) and - html_entity_decode() (to make
<b>Hello</b>
=> Hello)
Guess that should solve your problem ;)
As from the PHP Manual:
<?php
$orig = "I'll \"walk\" the <b>dog</b> now";
$a = htmlentities($orig);
$b = html_entity_decode($a);
echo $a; // I'll "walk" the <b>dog</b> now
echo $b; // I'll "walk" the <b>dog</b> now
?>
if you are doing an
<?php echo "<b>Hello World</b>" ?>
in your php page, it will be interpreted as html. So there is no problem ;)
精彩评论