首页 >后端开发 >php教程 >php查找问题

php查找问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原创
2016-06-23 14:09:32974浏览

怎么查找一个文章里包含有abc.com域名下的JS。
如一个字段时有XXXXXXXXXXX <script></script>XXXXXXXsdfa


回复讨论(解决方案)

用正则吧,无敌的正则帮你匹配,你只要做个判断匹配到就输出,正则现在本人不会写,可以在这里求诸大神们帮忙

$s=<<<txt如一个字段时有XXXXXXXXXXX<script src='http://www.abc.com/js/aaa.js' language='javascript'></script>XXXXXXX<a href="www.abc.com">sdfa</a><script src='http://www.def.com/js/bbb.js' language='javascript'>txt;preg_match_all("/<script[^>]*src='.+abc\.com[^>]+>/sU",$s,$m);print_r($m[0]);

Array
(
    [0] => <script> <br /> ) </script>

$s=<<<txt如一个字段时有XXXXXXXXXXX<script src='http://www.abc.com/js/aaa.js' language='javascript'></script>XXXXXXX<a href="www.abc.com">sdfa</a><script src='http://www.def.com/js/bbb.js' language='javascript'>txt;preg_match_all("/<script[^>]*src='.+abc\.com[^>]+>/sU",$s,$m);print_r($m[0]);

Array
(
    [0] => <script> <br /> ) <br /> 输出时少了</script>

preg_match_all("/<script>]*src='.+abc\.com[^>]+><\/script>/sU",$s,$m); </script>

但是你主贴中并没有套红  
要懂得尊重别人!!!


$s=<<<txt如一个字段时有XXXXXXXXXXX<script src='http://www.abc.com/js/aaa.js' language='javascript'></script>XXXXXXX<a href="www.abc.com">sdfa</a><script src='http://www.def.com/js/bbb.js' language='javascript'>txt;preg_match_all("/<script[^>]*src='.+abc\.com[^>]+>/sU",$s,$m);print_r($m[0]);

Array
(
    [0] => <script> <br /> ) <br /> 输出时少了</script>

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn