<a class="pdf" href="http://www.feedbooks.com/book/4384.pdf">PDF</a>
如何匹配出此链接中的href后面的连接地址

解决方案 »

  1.   


    $str = '<a class="pdf" href="http://www.feedbooks.com/book/4384.pdf">PDF</a>';if(preg_match('|<a class="pdf" href="(.*?)">PDF</a>|ims',$str,$match)){
    print_r($match[1]);
    }
      

  2.   


    $s = '<a class="pdf" href="http://www.feedbooks.com/book/4384.pdf">PDF</a>';
    preg_match("/<a[^<>]*href=\"([^\"]+)\"[^<>]*>/i", $s, $matches);
    echo $matches[1];
      

  3.   

    问题补充: 刚才忘了说了,要求匹配的是在一个网页中找到该标签中的href链接地址
      

  4.   

    $str='<a class="pdf" href="http://www.feedbooks.com/book/4384.pdf">PDF</a>';
     preg_match_all('/<a\s.*class=\"pdf\" href=\"(.*)\"/i',$str,$match);
     print_r($match)
      

  5.   

    没有干扰的话应该没问题$str='<a class="pdf" href="http://www.feedbooks.com/book/4384.pdf">PDF</a>';
    preg_match_all('/<a class="pdf" href="([^"]+)"/i',$str,$matches);
    print_r($matches[1]);