首頁  >  文章  >  後端開發  >  PHP函数strip_tags(去除html)的bug

PHP函数strip_tags(去除html)的bug

WBOY
WBOY原創
2016-07-25 08:54:16964瀏覽
  1. //解决strip_tags的bug
  2. function fixtags ($text) {
  3. $text = htmlspecialchars($text);
  4. $text = preg_replace("/"/", ""\"", $text);
  5. $tags = "/<(!|)(\/|)(\w*)(\ |)(\w*)([\\\=]*)(?|(\")\""\"|)(?|(.*)?"(\")|)([\ ]?)(\/|)>/i";
  6. $replacement = "";
  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), '
    ');
    复制代码


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn