• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php 正则替换有关问题

php 搞代码 3年前 (2022-01-24) 27次浏览 已收录 0个评论

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 /><!---ecms [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><script type=\"text/javascript\"><br />var _bdhmProtocol = ((\"https:\" == document.location.protocol) ? \" https://\" : \" http://\");<br />document.write(unescape(\"%3Cscript src='\" + _bdhmProtocol + \"hm.baidu.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 /><!---ecms [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><script type=\"text/javascript\"><br />var _bdhmProtocol = ((\"https:\" == document.location.protocol) ? \" https://\" : \" http://\");<br />document.write(unescape(\"%3Cscript src='\" + _bdhmProtocol + \"hm.baidu.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 /><!---ecms [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='roS2qY<em style="color:transparent">本文来源[email protected]搞@^&代*@码)网9</em><strong>搞代gaodaima码</strong>SKuPqZB7rZmvfpZy';<br /><br /></script><br /><span><script type=\"text/javascript\"><br />var _bdhmProtocol = ((\"https:\" == document.location.protocol) ? \" https://\" : \" http://\");<br />document.write(unescape(\"%3Cscript src='\" + _bdhmProtocol + \"hm.baidu.com/h.js?28' type='text/javascript'%3E%3C/script%3E\"));<br /></script></span><br />2222222222222<br />

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php 正则替换有关问题
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址