Home > Backend Development > PHP Tutorial > :这个a标签的正则怎么写?

:这个a标签的正则怎么写?

WBOY
Release: 2016-06-23 13:32:27
Original
1193 people have browsed it

情感剧场:爱情公寓精装版
剧情

只想匹配class为black的超链接,不想匹配 class="font12-orange"

请问大神们,正则怎么写?


回复讨论(解决方案)

$str = <<<EOF<a href="http://jq.tvsou.com/introhtml/14/index_1468.htm" target="_blank" class="black">情感剧场:爱情公寓精装版</a><a href="http://jq.tvsou.com/introhtml/730/index_73026.htm" target="_blank" class="font12-orange">剧情</a>EOF;preg_match('/<a href="([^"]+?)"[^>]+?class="black">(.+?)<\/a>/i',$str,$m);echo "<pre class="brush:php;toolbar:false">";print_r($m);echo "
Copy after login
";/*Array( [0] => 情感剧场:爱情公寓精装版 [1] => http://jq.tvsou.com/introhtml/14/index_1468.htm [2] => 情感剧场:爱情公寓精装版)*/

$zz='/(.*)?<\/a>/';

$str =<<<FDIPZONE <a href="http://jq.tvsou.com/introhtml/14/index_1468.htm" target="_blank" class="black">情感剧场:爱情公寓精装版</a><a href="http://jq.tvsou.com/introhtml/730/index_73026.htm" target="_blank" class="font12-orange">剧情</a> <a href="http://jq.tvsou.com/introhtml/14/index_1468.htm" target="_blank" class="black">情感剧场:爱情公寓精装版</a><a href="http://jq.tvsou.com/introhtml/730/index_73026.htm" target="_blank" class="font12-orange">剧情</a> <a href="http://jq.tvsou.com/introhtml/14/index_1468.htm" target="_blank" class="black">情感剧场:爱情公寓精装版</a><a href="http://jq.tvsou.com/introhtml/730/index_73026.htm" target="_blank" class="font12-orange">剧情</a>FDIPZONE;preg_match_all('/<a.*?href="(.*?)".*?class=\"font12-orange\"/si',$str, $matches); echo "<pre class="brush:php;toolbar:false">";print_r($matches[1]);echo "
Copy after login
";

正在学习正则表达式,学习了!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template