日期:2014-05-17  浏览次数:20433 次

帮忙写个正则表达式
		<dd class="clear">
    <a  target="_blank" title="爱丽丝cos" href="/cp/sK7A9su_Y29z.html">爱丽丝cos</a>
<a  target="_blank" title="爱丽丝连衣裙" href="/cp/sK7A9su_wazSwsi5.html">爱丽丝连衣裙</a>
<a  target="_blank" title="爱丽丝梦游仙境" href="/cp/sK7A9su_w87Tzs_JvrM.html">爱丽丝梦游仙境</a>
<a  target="_blank" title="爱丽丝疯狂回归" href="/cp/sK7A9su_t-i_8bvYuek.html">爱丽丝疯狂回归</a>
<a  target="_blank" title="爱丽丝花盆" href="/cp/sK7A9su_u6jF6A.html">爱丽丝花盆</a>
<a  target="_blank" title="爱丽丝手办" href="/cp/sK7A9su_ytaw7A.html">爱丽丝手办</a>
<a  target="_blank" title="alice" href="/cp/YWxpY2U.html">alice</a>
<a  target="_blank" title="女仆" href="/cp/xa7GzQ.html">女仆</a>
<a  target="_blank" title="爱丽丝学园" href="/cp/sK7A9su_0afUsA.html">爱丽丝学园</a>
<a  target="_blank" title="爱丽丝菲尔" href="/cp/sK7A9su_t8a2-w.html">爱丽丝菲尔</a>
<a  target="_blank" title="爱丽丝手包" href="/cp/sK7A9su_ytaw_A.html">爱丽丝手包</a>
<a  target="_blank" title="爱丽丝复古" href="/cp/sK7A9su_uLS5xQ.html">爱丽丝复古</a>
</dd>

我现在要取这个页面的<dd class="clear">到</dd>之间这段内容里的title的值和href的值,因为这个页面其他地方也有这种格式,所以现在直接用
$contents_key = '~<a  target="_blank" title="(.*?)" href="(.*?)">~';
preg_match_all($contents_key,$html,$contentskey);
这样会把dd标签外的相同格式的也包含进来,问下这个正则应该怎么写?

------解决方案--------------------
$s=<<<div
agfdafg
<dd class="clear">
                                                   <a  target="_blank" title="爱丽丝cos" href="/cp/sK7A9su_Y29z.html">爱丽丝cos</a>
                            <a  target="_blank" title="爱丽丝连衣裙" href="/cp/sK7A9su_wazSwsi5.html">爱丽丝连衣裙</a>