Heim  >  Artikel  >  Backend-Entwicklung  >  PHP函数strip_tags(去除html)的bug

PHP函数strip_tags(去除html)的bug

WBOY
WBOYOriginal
2016-07-25 08:54:16964Durchsuche
  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), '
    ');
    复制代码


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn