紧急求救,关于正则表达式的问题
本帖最后由 jxdyzwh 于 2013-03-28 15:35:54 编辑
<dd class="dd02" id="travel_city02">
<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>
</dd>
上面那段代码,我想提取城市名称和链接,应该如果操作,请好心人帮忙,非常感谢,我对正则表达式不是很了解
正则表达式
------解决方案--------------------preg_match_all('/<a[^>]+href="?([^>"]+)"?\s*[^>]*>(.+?)<\/a>/i',$data,$arr);
------解决方案--------------------把所有的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/scenery