这样肯定得不到你的链接。
因为上面 的正则是有 ^,$的限制。
将正则改成:
preg_match("/http.*www\.abc123\.com\.cn\/m\/(\w{3,})/is",$str,$m);
preg_match("/http:\/\/(\w{3,})\.service\.abc123\.com\//",$str2,$m2);

解决方案 »

  1.   

    谢谢,我试了下似乎不行。比如我抓CSDN的博客首页,将那个页面里面所有的博客超链接抓取。<?php$url = 'http://blog.csdn.net/default.html';
    $str = file_get_contents($url); 
    preg_match("/http.*blog\.csdn\.net\/(\w{3,})/is",$str,$m);
    print_r($m);?>可这样写输出的是CSDN博客首页的内容,而不是一个个的链接,请大家赐教。
      

  2.   

    <?php$url = 'http://blog.csdn.net/';
    $str = file_get_contents($url); 
    preg_match("/http.*blog\.csdn\.net\/(\w{3,})/is",$str,$m);
    print_r($m);?>这样取出不是满足
    http://blog.csdn.net/这里不限/

    http://这里不限.blog.csdn.net/
      

  3.   

    <?php$url = 'http://blog.csdn.net/';
    $str = file_get_contents($url); 
    preg_match("/http.*blog\.csdn\.net\/(\w{3,})/is",$str,$m);
    print_r($m);?>这样取出不是满足
    http://blog.csdn.net/这里不限/

    http://这里不限.csdn.net/
      

  4.   

    先不说“http://这里不限.blog.csdn.net/”在http://blog.csdn.net/这个页面上有“http://blog.csdn.net/这里不限/”的超链接不知应该如何全部取出?
      

  5.   

    <?php$url = 'http://blog.csdn.net/default.html';
    $str = file_get_contents($url);
    preg_match_all("|http://blog\.csdn\.net/\w+|i",$str,$m);
    print_r($m);?>不知道对不。。
      

  6.   

    首先确保你的$str有值。
    再给你个例子:
    $str = <<<OF
    href="http://www.csdn.net/ibma/
    href="http://www.csdn.net/ibmb/
    href="http://www.csdn.net/ibmc/
    href="http://www.csdn.net/ibmd/
    OF;preg_match_all("/http:\/\/(.*?)\/\w{3,}\//s",$str,$m);
    print_r($m);
      

  7.   

    成了,呵呵.还有几个小问题就留给自己了,谢谢大家的帮助.特别谢谢:willko(珂[新手]->努力学习)