本帖最后由 jxdyzwh 于 2013-03-28 15:35:54 编辑

解决方案 »

  1. preg_match_all('/<a[^>]+href="?([^>"]+)"?\s*[^>]*>(.+?)<\/a>/i',$data,$arr); 
      

  2. 把所有的span内容定义成一个字符串,然后写一个正则表达式匹配,返回一个数组,打印数组,看到结构,根据需要取值:
    <?php
    $str="<span class='dt_sp01'><a href='javascript:void(0);'>全部</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_96__0_0_0.html'>中山</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_97__0_0_0.html'>珠海</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_77__0_0_0.html'>潮州</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_78__0_0_0.html'>东莞</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_79__0_0_0.html'>佛山</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_85__0_0_0.html'>茂名</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_84__0_0_0.html'>揭阳</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_87__0_0_0.html'>清远</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_86__0_0_0.html'>梅州</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_81__0_0_0.html'>河源</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_80__0_0_0.html'>广州</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_83__0_0_0.html'>江门</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_82__0_0_0.html'>惠州</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_93__0_0_0.html'>云浮</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_92__0_0_0.html'>阳江</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_95__0_0_0.html'>肇庆</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_94__0_0_0.html'>湛江</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_89__0_0_0.html'>汕尾</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_88__0_0_0.html'>汕头</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_91__0_0_0.html'>深圳</a></span><span class='city_name'><a href='/scenery/scenerysearchlist_6_90__0_0_0.html'>韶关</a></span>";
    $reg="/\<a\s*href=\'(.*?)\'\>(.*?)\<\/a\>/mi";
    preg_match_all($reg,$str,$arr);
    echo "<pre>";
    print_r($arr);
    echo "</pre>";
    ?>
      


  3. preg_match_all('/<a[^>]+href=["\']?([^>"\']+)["\']?\s*[^>]*>(.+?)<\/a>/i', $str, $arr, PREG_SET_ORDER);