preg_match_all("/href\s*=\s*(['\"]?)(.+?)\\1/i",$str,$arr);
print_r($arr[2]); 
不知道为什么要加 PREG_SET_ORDER 属性,把结果聚在一起不是更容易处理吗?

解决方案 »

  1.   

    preg_match_all("/href\s*=\s*(['\"]?)(.+?)\\1/i",$str,$arr); 
    print_r($arr[2]); 
    这个好像也不行,输出如下:
    Array
    (
        [0] => Array
            (
                [0] => href=h
                [1] => href=h
                [2] => href=h
                [3] => href=h
                [4] => href=h
                [5] => href=h
                [6] => href="http://passport.baidu.com/?login&tpl=mn&u='+escape(location.href)+'"
                [7] => href=h
                [8] => href=/
                [9] => href=/
                [10] => href=h
                [11] => href="http://www.hao123.com"
                [12] => href=/
                [13] => href=h
                [14] => href=h
                [15] => href=h
                [16] => href=/
                [17] => href=h
                [18] => href=h
                [19] => href=h
                [20] => href=h
            )    [1] => Array
            (
                [0] => 
                [1] => 
                [2] => 
                [3] => 
                [4] => 
                [5] => 
                [6] => "
                [7] => 
                [8] => 
                [9] => 
                [10] => 
                [11] => "
                [12] => 
                [13] => 
                [14] => 
                [15] => 
                [16] => 
                [17] => 
                [18] => 
                [19] => 
                [20] => 
            )    [2] => Array
            (
                [0] => h
                [1] => h
                [2] => h
                [3] => h
                [4] => h
                [5] => h
                [6] => http://passport.baidu.com/?login&tpl=mn&u='+escape(location.href)+'
                [7] => h
                [8] => /
                [9] => /
                [10] => h
                [11] => http://www.hao123.com
                [12] => /
                [13] => h
                [14] => h
                [15] => h
                [16] => /
                [17] => h
                [18] => h
                [19] => h
                [20] => h
            ))