PHP函數strip_tags(去除html)的bug

WBOY
發布: 2016-07-25 08:54:16
原創
983 人瀏覽過
  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), '
    ');
复制代码


來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!