开发者

use string html text to html

开发者 https://www.devze.com 2023-03-02 21:26 出处:网络
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

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 &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; 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 ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消