用正则表达式替换HTML实体

时间:2012-01-10 10:57:05

标签: php regex preg-replace

我想在PHP中使用正则表达式来查找所有HTML实体,例如"<br /> <br /> ..etc. ",以便从长字符串中删除它们。

3 个答案:

答案 0 :(得分:19)

这个删除了alpha,decimal和hex HTML实体:

$text = preg_replace('/&(?:[a-z\d]+|#\d+|#x[a-f\d]+);/i', '', $text);

答案 1 :(得分:-1)

尝试使用这个正则表达式... [^ \ s] *正在捕捉其他许多废话......

$text = preg_replace("/&(?:[a-z0-9]{2,8}|#[0-9]{2,3}+);/i", '', $text);

答案 2 :(得分:-2)

尝试使用strip_tags函数,此处不需要正则表达式

相关问题