【问题标题】:What does &lt;/p&gt; mean in query results?查询结果中的</p>是什么意思?
【发布时间】:2013-09-13 02:59:41
【问题描述】:

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

SELECT description 
FROM TABLE
WHERE id = 111;

在我的结果中,我得到:

&lt;p&gt;Blah blah description is here blah blah&lt;p&gt;

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

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

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

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

如何去掉描述开头和结尾处的&lt;p&gt; 标签?如果有帮助,我正在为我的页面使用concrete5。谢谢!

【问题讨论】:

  • 可能是concrete5插入的。
  • 您的文本中有编码的 html 实体,例如您已经以编码形式存储了 html。

标签: php html mysql


【解决方案1】:

您可以使用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 这样的来源,否则您将需要存储纯文本。这听起来像是需要明文的情况。

【讨论】:

  • 修复了它。我没有创建数据库,但描述是通过使用我相信的文本框的在线表格输入的。也许这就是导致 html 实体存储在 BD 中的原因。哦,好吧,它现在修好了,我学到了一些东西!谢谢大家!
【解决方案2】:

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

echo strip_tags(html_entity_decode($yourString));

【讨论】:

    【解决方案3】:

    使用这个

    htmlspecialchars_decode(html_entity_decode($var))
    

    htmlentities(html_entity_decode(strip_tags($var)))
    

    为我工作

    【讨论】:

      猜你喜欢
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-14
      • 2014-09-21
      • 2012-11-02
      相关资源
      最近更新 更多