使用字符串HTML文本到HTML


use string html text to html

问题是这样的,我有一些文本,我从DB带来的。该信息被记录为HTML。当我带来的信息,它来作为"<b>hello world</b>"我的意思是,它来作为字符串的所有html,我想使用字符串作为html。我想在php中有一个函数,但我没有找到。

的例子:我有"<b>hello world</b>",需要hello world

您可以使用:

echo htmlspecialchars_decode($var);

我认为你使用htmlspecialchar()当你插入到数据库

参见函数

  • htmlentitites()(使Hello => <b>Hello</b>)和
  • html_entity_decode()(使<b>Hello</b> => Hello)

我猜这应该能解决你的问题;)

来自PHP手册:

<?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
?>

<?php echo "<b>Hello World</b>" ?>

在PHP页面中,它将被解释为html。所以没有问题;)