当前位置:Gxlcms > PHP教程 > PHP函数strip_tags(去除html)的bug

PHP函数strip_tags(去除html)的bug

时间:2021-07-01 10:21:17 帮助过:20人阅读

  1. //解决strip_tags的bug
  2. function fixtags ($text) {
  3. $text = htmlspecialchars($text);
  4. $text = preg_replace("/"/", ""\"", $text);
  5. $tags = "/<(!|)(\/|)(\w*)(\ |)(\w*)([\\\=]*)(?|(\")\""\"|)(?|(.*)?"(\")|)([\ ]?)(\/|)>/i";
  6. $replacement = "<$1$2$3$4$5$6$7$8$9$10$11>";
  7. $text = preg_replace($tags, $replacement, $text);
  8. $text = preg_replace("/=\"\"/", "=", $text);
  9. $text = preg_replace("/"\"/", "\"", $text);
  10. return $text;
  11. }

使用方法:

  1. strip_tags(fixtags($string), '');

人气教程排行