strip_tags in php 没有帮助,需要更好的选择

strip_tags in php doesnt help, need a better alternative

我得到一个表格值,我需要在其中去除 html 标签而不是其他东西。

示例:我在 textarea 中传递以下内容

<h1> test </h1> Testing <5 years or >2 years.

我需要得到以下结果

test Testing <5 years or >2 years.

当我尝试剥离标签时,它也删除了我不想要的 5 年。非常感谢那些对此提供帮助的人。!

您需要预处理 HTML 以在调用 strip_tags 之前将不包含有效 HTML 标记的左尖括号和右尖括号转换为实体。有很多方法可以做到这一点,但最简单和最可靠的可能是使用 HTML Purifier. HTML purifier is smart enough to entity encode the greater-than and less-than in your string, while leaving the H1 tags intact. You can then strip tags, and if you need to have the angle brackets restored, use html_entity_decode.