Home  >  Article  >  Backend Development  >  Bug in PHP function strip_tags (remove html)

Bug in PHP function strip_tags (remove html)

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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn