Home  >  Article  >  Backend Development  >  这个a标签的正则如何写

这个a标签的正则如何写

WBOY
WBOYOriginal
2016-06-13 12:22:13847browse

求助:这个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 "
";
/*
Array
(
    [0] => 情感剧场:爱情公寓精装版
    [1] => http://jq.tvsou.com/introhtml/14/index_1468.htm
    [2] => 情感剧场:爱情公寓精装版
)
*/

------解决思路----------------------
<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 "
";

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn