Maison >développement back-end >tutoriel php >这个a标签的正则如何写
求助:这个a标签的正则怎么写?
情感剧场:爱情公寓精装版
剧情
只想匹配class为black的超链接,不想匹配 class="font12-orange"
请问大神们,正则怎么写?
------解决思路----------------------
<br />$str = <<<EOF<br /><a href="http://jq.tvsou.com/introhtml/14/index_1468.htm" target="_blank" class="black">情感剧场:爱情公寓精装版</a><br /><a href="http://jq.tvsou.com/introhtml/730/index_73026.htm" target="_blank" class="font12-orange">剧情</a><br />EOF;<br /><br />preg_match('/<a href="([^"]+?)"[^>]+?class="black">(.+?)<\/a>/i',$str,$m);<br /><br />echo "<pre class="brush:php;toolbar:false">";<br />print_r($m);<br />echo "";
<br />$str =<<<FDIPZONE<br /> <a href="http://jq.tvsou.com/introhtml/14/index_1468.htm" target="_blank" class="black">情感剧场:爱情公寓精装版</a><br /><a href="http://jq.tvsou.com/introhtml/730/index_73026.htm" target="_blank" class="font12-orange">剧情</a><br /> <a href="http://jq.tvsou.com/introhtml/14/index_1468.htm" target="_blank" class="black">情感剧场:爱情公寓精装版</a><br /><a href="http://jq.tvsou.com/introhtml/730/index_73026.htm" target="_blank" class="font12-orange">剧情</a><br /> <a href="http://jq.tvsou.com/introhtml/14/index_1468.htm" target="_blank" class="black">情感剧场:爱情公寓精装版</a><br /><a href="http://jq.tvsou.com/introhtml/730/index_73026.htm" target="_blank" class="font12-orange">剧情</a><br />FDIPZONE;<br /><br />preg_match_all('/<a.*?href="(.*?)".*?class=\"font12-orange\"/si',$str, $matches);<br /> <br />echo "<pre class="brush:php;toolbar:false">";<br />print_r($matches[1]);<br />echo "";