php 正则替换问题
本帖最后由 wljk506 于 2014-09-24 13:14:44 编辑 替换 script 代码部分注释//....(//开始到行尾) 为空
<br />$str="<br /><script> document.write(unescape(\"%3Cspan id='szgs_stat_icon_2'%3E%3C/span%3E%3Cscript src='http://www.szgswljg.gov.cn/sendMark?siteid=2&website=z.com' type='text/javascript'%3E%3C/script%3E\")); </script><br /><script type=\"text/javascript\" src=\"http://z.com/a.js\"></script><br /><!--[if IE 6]><script type=\"text/javascript\" src=\"http://z.com/pngfix.js\"></script><![endif]--><br /><script src=\"http://z.com/jquery.uploadify.3.2.1.js\"></script><br /><script><br />//true56546456<br />function showTips(type,msg,d){//true存在文件,false不存在文件<br />$('#'+type).parent().find('span').text(msg).removeClass('Validform_right').addClass('Validform_wrong');<br />}<br />//trueddddddddd<br />var uploadFile=false,//true存在文件,false不存在文件<br />dia,upToken='roS2qYSKuPqZB7rZmvfpZy';<br />//true存在文件,false不存在文件<br /></script><br /><span style=\"display:None;\"><script type=\"text/javascript\"><br />var _bdhmProtocol = ((\"https:\" == document.location.protocol) ? \" https://\" : \" http://\");<br />document.write(unescape(\"%3Cscript src='\" + _bdhmProtocol + \"m.sbmmt.com/h.js?28' type='text/javascript'%3E%3C/script%3E\"));<br /></script></span><br />2222222222222<br />";<br />
ログイン後にコピー
我弄了一个,不正确
<br />$str=preg_replace('/(<script>[\s\S]*?)[^(http:|https:)]\/\/.*?\n([\S\s]*?<\/script>)/si','$1$2',$str);<br />echo $str;<br />
ログイン後にコピー
------解决思路----------------------$s =<<< TXT<br /><script> document.write(unescape(\"%3Cspan id='szgs_stat_icon_2'%3E%3C/span%3E%3Cscript src='http://www.szgswljg.gov.cn/sendMark?siteid=2&website=z.com' type='text/javascript'%3E%3C/script%3E\")); </script><br /><script type=\"text/javascript\" src=\"http://z.com/a.js\"></script><br /><!--[if IE 6]><script type=\"text/javascript\" src=\"http://z.com/pngfix.js\"></script><![endif]--><br /><script src=\"http://z.com/jquery.uploadify.3.2.1.js\"></script><br /><script><br />//true56546456<br />function showTips(type,msg,d){//true存在文件,false不存在文件<br />$('#'+type).parent().find('span').text(msg).removeClass('Validform_right').addClass('Validform_wrong');<br />}<br />//trueddddddddd<br />var uploadFile=false,//true存在文件,false不存在文件<br />dia,upToken='roS2qYSKuPqZB7rZmvfpZy';<br />//true存在文件,false不存在文件<br /></script><br /><span style=\"display:None;\"><script type=\"text/javascript\"><br />var _bdhmProtocol = ((\"https:\" == document.location.protocol) ? \" https://\" : \" http://\");<br />document.write(unescape(\"%3Cscript src='\" + _bdhmProtocol + \"m.sbmmt.com/h.js?28' type='text/javascript'%3E%3C/script%3E\"));<br /></script></span><br />2222222222222<br />TXT;<br />echo preg_replace('#([^:])//.+#m', '$1', $s);
ログイン後にコピー
<script> document.write(unescape(\"%3Cspan id='szgs_stat_icon_2'%3E%3C/span%3E%3Cscript src='http://www.szgswljg.gov.cn/sendMark?siteid=2&website=z.com' type='text/javascript'%3E%3C/script%3E\")); </script><br /><script type=\"text/javascript\" src=\"http://z.com/a.js\"></script><br /><!--[if IE 6]><script type=\"text/javascript\" src=\"http://z.com/pngfix.js\"></script><![endif]--><br /><script src=\"http://z.com/jquery.uploadify.3.2.1.js\"></script><br /><script><br /><br />function showTips(type,msg,d){<br />$('#'+type).parent().find('span').text(msg).removeClass('Validform_right').addClass('Validform_wrong');<br />}<br /><br />var uploadFile=false,<br />dia,upToken='roS2qYSKuPqZB7rZmvfpZy';<br /><br /></script><br /><span style=\"display:None;\"><script type=\"text/javascript\"><br />var _bdhmProtocol = ((\"https:\" == document.location.protocol) ? \" https://\" : \" http://\");<br />document.write(unescape(\"%3Cscript src='\" + _bdhmProtocol + \"m.sbmmt.com/h.js?28' type='text/javascript'%3E%3C/script%3E\"));<br /></script></span><br />2222222222222<br />
ログイン後にコピー