Discuz教程网

asp中去除html中style,javascript,css代码

[复制链接]
authicon dly 发表于 2011-9-14 09:03:49 | 显示全部楼层 |阅读模式
asp函数代码
  1. <%
  2. Function RemoveHTML(str)
  3. Dim objRegExp, Match,strHTML
  4. if isnull(str) then
  5. str=""
  6. end if
  7. strHTML=str
  8. strHTML=replace(replace(replace(strHTML,vblf,""),vbcr,""),vbcrlf,"")


  9. Set objRegExp = New Regexp
  10. objRegExp.IgnoreCase = True
  11. objRegExp.Global = True

  12. objRegExp.Pattern = "<script[^>]*?>.*?</script>"
  13. strHTML = objRegExp.Replace(strHTML,"")

  14. objRegExp.Pattern = "<style[^>]*?>.*?</style>"
  15. strHTML = objRegExp.Replace(strHTML,"")

  16. objRegExp.Pattern = "<.+?>"
  17. strHTML = objRegExp.Replace(strHTML,"")

  18. Set objRegExp = Nothing

  19. RemoveHTML=strHTML
  20. End Function
  21. %>
复制代码

php中的代码
  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. "\1",
  22. """,
  23. "&",
  24. "<",
  25. ">",
  26. " ",
  27. chr(161),
  28. chr(162),
  29. chr(163),
  30. chr(169),
  31. "chr(\1)");
  32. //$document为需要处理字符串,如果来源为文件可以$document = file_get_contents('http://www.sina.com.cn');
  33. $out = preg_replace($search, $replace, $document);
  34. echo $out;
  35. ?>
复制代码

存为get.php即可。



上一篇:做了CDN加速的ASP网站获取用户真实IP程序
下一篇:一个较新的ASP后门服务端实现代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 12:40

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表