Home > Backend Development > PHP Tutorial > php 正则替换有关问题

php 正则替换有关问题

WBOY
Release: 2016-06-13 12:06:57
Original
818 people have browsed it

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 />
Copy after login

我弄了一个,不正确
<br />$str=preg_replace('/(<script>[\s\S]*?)[^(http:|https:)]\/\/.*?\n([\S\s]*?<\/script>)/si','$1$2',$str);<br />echo $str;<br />
Copy after login

------解决思路----------------------
$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);
Copy after login
<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 />
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template