正则获取源码中的url解决办法

WBOY
Release: 2016-06-13 10:53:14
Original
1127 people have browsed it

正则获取源码中的url

  • 打开

  • 源码中有这么一段,我想获取其中的url /plus/ajax.php?open=2&id=826186 php正则怎么获取,新手,望指点一下


    ------解决方案--------------------
    PHP code
    $s ='
    Copy after login
  • 打开
  • ';preg_match_all('/href="(.*?)"/i',$s,$arr);print_r($arr);
    ------解决方案--------------------
    PHP code
    if(preg_match_all('/
    Copy after login
  • .*?[^/is',$s,$match)){ //print_r($match); $tmp = $match[1][0]; //$tmp 就是你要的部分 //echo $tmp ;}
    ------解决方案--------------------
    csdn高手太多了,鬱悶,我還沒來得及回答就已經有人搶先了.
    ------解决方案--------------------
    探讨

    PHP code

    if(preg_match_all('/
  • .*?[^/is',$s,$match)){
    //print_r($match);
    $tmp = $match[1][0]; //$tmp 就是你要的部分
    //echo $tmp ;
    }

  • ------解决方案--------------------
    PHP code
    //哥也来个兼容性强大点的吧。。preg_match_all('/<a>]*href\s*=\s*[\'"]([^\'">]*)[\'"]/i',$string,$matches);var_dump($matches[1]);<br><font color="#e78608">------解决方案--------------------</font><br>见到这种问题我真的不想回答,建议你自己好好看看正则表达式……<br><font color="#e78608">------解决方案--------------------</font><br></a>
    Copy after login
    探讨

    PHP code

    //哥也来个兼容性强大点的吧。。

    preg_match_all('/]*href\s*=\s*[\'"]([^\'">]*)[\'"]/i',$string,$matches);

    var_dump($matches[1]);
  • 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
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!