PHP函数strip_tags(去除html)的bug
时间:2021-07-01 10:21:17
帮助过:20人阅读
- //解决strip_tags的bug
- function fixtags ($text) {
- $text = htmlspecialchars($text);
- $text = preg_replace("/"/", ""\"", $text);
- $tags = "/<(!|)(\/|)(\w*)(\ |)(\w*)([\\\=]*)(?|(\")\""\"|)(?|(.*)?"(\")|)([\ ]?)(\/|)>/i";
- $replacement = "<$1$2$3$4$5$6$7$8$9$10$11>";
- $text = preg_replace($tags, $replacement, $text);
- $text = preg_replace("/=\"\"/", "=", $text);
- $text = preg_replace("/"\"/", "\"", $text);
- return $text;
- }
使用方法:
- strip_tags(fixtags($string), '');
|