【问题标题】:How Get the Special Character list from a HTML string如何从 HTML 字符串中获取特殊字符列表
【发布时间】:2021-04-26 13:45:15
【问题描述】:

在我保存的数据库中,

<p>& sign test</p> <p><>greater than and less than</p>

我正在使用这些文件下载。我想将这些特殊字符 &amp;amp;&amp;lt;&amp;gt; 分别替换为 &amp;amp;&amp;lt;&amp;gt;

如何检测上述 html 内容中的特殊字符?

【问题讨论】:

  • 请出示您已经尝试过的代码。
  • php strip_tags() 函数用于获取文本
  • 你能解释更多以了解你真正需要什么
  • 在表格中我保存了上面的 html 内容。但并不是所有的html都有特殊字符,我想首先获取特殊字符并将它们转换为html。目前我正在获取文本,但我只想检测该文本中的特殊字符,我可以从给定的文本中获取一些特殊字符数组吗?

标签: php html phpdocx


【解决方案1】:
$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

如果您不想将 html 标签转换为 unicode,也可以使用自定义函数:

$text = str_replace(array("&quot;", "&amp;"), array("\"", "&"), $text);

【讨论】:

  • 在我的输入中,它有 html 标签,它们也正在转换为 < >
  • 对于您提供的上述代码,我也在打印

    标签,我想删除它们。

猜你喜欢
  • 2016-10-01
  • 1970-01-01
  • 2020-08-26
  • 1970-01-01
  • 2021-08-18
  • 1970-01-01
  • 1970-01-01
  • 2016-02-28
  • 2019-06-16
相关资源
最近更新 更多