我有一堆 HTML 数据,我正在使用 PHP 将这些数据写入 PDF 文件。在 PDF 中,我希望所有的 HTML 都被剥离和清理。例如:
<ul>
<li>First list item</li>
<li>Second list item which is quite a bit longer</li>
<li>List item with apostrophe 's 's</li>
</ul>
应该变成:
First list item
Second list item which is quite a bit longer
List item with apostrophe 's 's
但是,如果我简单地使用 strip_tags()
,我会得到这样的结果:
First list item

Second list item which is quite a bit
longer

List item with apostrophe ’s ’s
还要注意输出的缩进。
关于如何将 HTML 正确清理为没有乱七八糟的空白和奇怪字符的漂亮、干净的字符串的任何提示?
谢谢:)
最佳答案
字符似乎是 html 实体。尝试:
html_entity_decode( strip_tags( $my_html_code ) );
关于php - 使用 PHP 清理 HTML 以创建干净的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10444509/