首頁 >後端開發 >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