'"]*).*js/i"),$code,$link);"/> '"]*).*js/i"),$code,$link);">

Home  >  Article  >  Backend Development  >  请问下preg_match的有关问题

请问下preg_match的有关问题

WBOY
WBOYOriginal
2016-06-13 10:14:28985browse

请教下preg_match的问题
请教下各位大牛,如何抓取一个页面然后匹配页面中的所有链接是js的。目前我这么做的

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->function getLink($code){  preg_match_all("/src=[\'\"]{0,1}([^>\'\"]*).*js/i"),$code,$link);  return $link[1];}


可是调用的时候碰到页面理的js链接如下的时候就输出不正常了。

http://www.test.com/1.js?eGo  
-----这个只能输出http://www.test.com/1.

http://www.test.com/2.js
-----这个能正常输出http://www.test.com/2.js

求指点

------解决方案--------------------
preg_match_all("/src=[\'\"]{0,1}([^>\'\"]*.*js?)/i"),$code,$link); //这样呢?
------解决方案--------------------
preg_match_all("/src=[\'\"]{0,1}([^>\'\"]*.*js)/iU",$code,$link);

结果中会包含 mre_src 部分的内容,若不想要,则
preg_match_all("/\bsrc=[\'\"]{0,1}([^>\'\"]*.*js)/iU",$s,$link);

------解决方案--------------------
PHP code
$str='<script src="test.js" type="text/javascript" mre_src="test.js"></script>';$pattern='/\bsrc=[\'"]?([^"\']+\.js)/U';preg_match_all($pattern,$str,$matches);print_r($matches);<div class="clear">
                 
              
              
        
            </div>
Statement:
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