php过滤纯文本,过滤html返回纯文本 - 古月容博客-php个人技术博客-技术交流分享...

2018-3-21

分类: 随心记

阅读(553)

评论(0)

public static string CheckStr(string html)

{

System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"

System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[/s/S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" no[/s/S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"

", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"/]+/>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"

", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"

", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

html = regex1.Replace(html, ""); //过滤标记

html = regex2.Replace(html, ""); //过滤href=javascript: () 属性

html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件

html = regex4.Replace(html, ""); //过滤iframe

html = regex5.Replace(html, ""); //过滤frameset

html = regex6.Replace(html, ""); //过滤frameset

html = regex7.Replace(html, ""); //过滤frameset

html = regex8.Replace(html, ""); //过滤frameset

html = regex9.Replace(html, "");

html = html.Replace(" ", "");

html = html.Replace("", "");

html = html.Replace("", "");

return html;

}

方法在其他论坛看到的具体是哪里不记得了。

×

b3e7df84771e345a649b6022a236c38d.png

感谢您的支持,我们会一直保持!

请土豪扫码随意打赏

gNRpWobSGtA3gAAAABJRU5ErkJggg==

kEqY9rO0Y495AAAAAASUVORK5CYII=

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

fe20d2a719cd7402dc2aa72bf3f83efe.png

*

*

表情

提交评论

46fc3d594402d59a998062c3e8568de9.pngdb58455ece3213c3c696d1e76bd7a981.pnga172664d4a29a425385d9c6e57964c36.png898d69da73afa04e61d1fc0412b9a5c3.png7c5826abd6cf61c3e1e78a74031e54fd.pngfc620e132452f4b33eb7e1ecea17116d.pngf41eaa8612df17b55548a16f72e3b70b.pngc7ea3c05b67a9930af4c2725e4a538de.png29030ab491ce2fa85ae51e5667cd6770.pnga5ab74b90d4d46857ac4caeddb05f8c9.pngce5b4359d8b5d908d9d983ade407e998.pnge6cca78294ab6018b500504d1c064faf.pngf93e073b1d91bd891f403511370e120c.png0044f8547d9dc7a808085d9fe518630c.pngf5c2ceeeb279f2f9ce9e55c4dd05260a.png5f7f270444b4f258b68eef59fa0dc0ad.png2b05d3e090fd8e59da8f416482adeed5.pngc3bb50d76d9cf8dcfde95b6f78d6c7e8.pngfb5cad3b0fe0681540fcfbb3c3814890.pngcd724a70049c9608957bad522f20fb05.pngc5dc516d6ec8ec609b5024ece1de4232.pngcc854db99c4e79a754ec9192e5c573dc.pngc33e57ee1afdac35e6a8ec2acd4ac874.pngb89202a3e7c6e253d69d45f5ac915e8c.pngeb4f7108e4079a1551dce1aff8e405e6.png098edcb22d2ab8461cad35cf33b46a0e.pngfe9bf270c6d7f68bba2614b0c9bab9f5.pnga063f4c722506f7f631eae2df81d7463.png730fbcf72d1a830dbe124835f20cb240.png66dbe222c5a078438939aca36c48559d.png

网友评论(0)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值