5

好的,我运行一个简单的查询,

SELECT description 
FROM TABLE
WHERE id = 111;

在我的结果中,我得到:

<p>Blah blah description is here blah blah<p>

然后当我使用 PHP 输出我的结果时:

echo '<ul>' . $row['description'] . '</ul>';

我在我的 html 页面上得到了这个:

<p>Blah blah description is here blah blah</p>

如何摆脱<p>描述开头和结尾的标签?如果有帮助,我正在为我的页面使用concrete5。谢谢!

4

3 回答 3

7

你可以用strip_tags它来摆脱 HTML。

$string = "&lt;p&gt;Blah blah description is here blah blah&lt;p&gt;";
$string = html_entity_decode($string);
$string = strip_tags($string);
echo $string; // Blah blah description is here blah blah

但是,您通常不应该将 HTML 存储在数据库中。除非输入来自像 WYSIWYG 这样的来源,否则您将需要存储纯文本。这听起来像是需要明文的情况。

于 2013-09-09T15:07:07.117 回答
6

这些是编码的 html 实体。要摆脱它们,您可以这样做:

echo strip_tags(html_entity_decode($yourString));
于 2013-09-09T15:07:04.553 回答
1

用这个

htmlspecialchars_decode(html_entity_decode($var))

或者

htmlentities(html_entity_decode(strip_tags($var)))

为我工作

于 2017-03-03T08:47:41.533 回答