【问题标题】:PHP cleanup "&$"PHP 清理“&$”
【发布时间】:2012-11-07 05:19:18
【问题描述】:

我正在尝试将 HTML 转换为纯文本。我收到很多&\#8217; &\#8220; 等。

我试过了:

  1. html2text命令行
  2. html_entity_decode + ENT_QUOTES | ENT_HTML401UTF-8
  3. html_entity_decode(htmlentities($str))
  4. strip_tags
  5. trim

它确实对清理其他东西有很大帮助,但那些 &\#8217; “ 没有得到修复。如何正确转换它们?

【问题讨论】:

  • 你的意思是’“吗?

标签: php html unicode


【解决方案1】:

你试过“htmlspecialchars_decode”吗

<?php
$str = "<p>this -&gt; &quot;</p>\n";
echo htmlspecialchars_decode($str);
// note that here the quotes aren't converted
echo htmlspecialchars_decode($str, ENT_NOQUOTES);
?>

上面的例子会输出:

<p>this -> "</p>
<p>this -> &quot;</p>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-28
    • 2012-10-15
    • 2011-08-17
    • 1970-01-01
    • 2012-12-08
    • 2015-08-16
    • 2015-08-13
    • 1970-01-01
    相关资源
    最近更新 更多