个人感觉已经很完美了,有朋友发信息问我
<a.* 为什么这样写答:是为了匹配<a id="a" href......>sfsdfsd</a>

解决方案 »

  1.   

    不知道你测试过没有http:// 应该为http:\/\/
    >]+).*>.*</[\s]*a[\s]*>/ 中间的/也不对
    你是不是测都没有侧过就发上来了[\s]* 表示什么意思和 \s*的区别是什么?(http://[^\s\"\'>]+).* 这样写对吗? 
    <a href="http://abc.com/abc.php"></a> U 表示匹配1次或0次, 只能匹配上http://a
    你这样写是不是会更好一些 (http:\/\/[^\s\"\'>]+)[\s\"\'>]>
      

  2.   


    <?php
    $content = file_get_contents("http://www.csdn.com"); 
    $pattern = "/<\s*?a[^>]+?href\s*?=\s*?([\"']?)\s*?([^\"'>]+?)\\1[^>]*?>.*?<\/\s*?a\s*?>/is";
    preg_match_all($pattern,$content,$mats);
    var_export($mats[2]);
    ?>
    a前后的空格大部分时候可以不需要考虑。
    这种容错性的需求是很小的。U是反转匹配数量。加上就不需要使用?来规避贪婪。不过不建议使用。
      

  3.   


    $pattern = "/<img.*?src[\s]*?=[\s]*?[\"\']?[\s]*?([^\s\"\'>]+\.(gif|jpg|jpeg|bmp|png))/is";