Heim > Backend-Entwicklung > PHP-Tutorial > php 正则替换有关问题

php 正则替换有关问题

WBOY
Freigeben: 2016-06-13 12:06:57
Original
827 Leute haben es durchsucht

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 + \"hm.baidu.com/h.js?28' type='text/javascript'%3E%3C/script%3E\"));<br /></script></span><br />2222222222222<br />";<br />
Nach dem Login kopieren

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

------解决思路----------------------
$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 + \"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);
Nach dem Login kopieren
<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 + \"hm.baidu.com/h.js?28' type='text/javascript'%3E%3C/script%3E\"));<br /></script></span><br />2222222222222<br />
Nach dem Login kopieren
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage