PHP头条
热点:

PHP 自定义函数:清除页面所有js,html,css代码


PHP 自定义函数:清除页面所有js,html,css代码
  1. <?php
  2. $search = array ("<script[^>]*?>.*?</script>si", // 去掉 javascript
  3. "<style[^>]*?>.*?</style>si", // 去掉 css
  4. "<[/!]*?[^<>]*?>si", // 去掉 HTML 标记
  5. "<!--[/!]*?[^<>]*?>si", // 去掉 注释标记
  6. "([rn])[s] ", // 去掉空白字符
  7. "&(quot|#34);i", // 替换 HTML 实体
  8. "&(amp|#38);i",
  9. "&(lt|#60);i",
  10. "&(gt|#62);i",
  11. "&(nbsp|#160);i",
  12. "&(iexcl|#161);i",
  13. "&(cent|#162);i",
  14. "&(pound|#163);i",
  15. "&(copy|#169);i",
  16. "&#(d );e"); // 作为 PHP 代码运行
  17. $replace = array ("",
  18. "",
  19. "",
  20. "",
  21. "[code]",
  22. """,
  23. "&",
  24. "<",
  25. ">",
  26. " ",
  27. chr(161),
  28. chr(162),
  29. chr(163),
  30. chr(169),
  31. "chr([code])");
  32. //$document为需要处理字符串,如果来源为文件可以$document = file_get_contents(http://www.sina.com.cn);
  33. $out = preg_replace($search, $replace, $document);
  34. echo $out;
  35. ?>

www.phpzy.comtrue/phprm/24109.htmlTechArticlePHP 自定义函数:清除页面所有js,html,css代码 PHP 自定义函数:清除页面所有js,html,css代码 ?php $search = array ("script[^]*?.*?/scriptsi", // 去掉 javascript "style[^]*?.*?/stylesi", // 去掉 css "[/!]*?[^]*?si"...

相关文章

    暂无相关文章

PHP之友评论

今天推荐