比如有 以下几个url
<a href=' http://www.baidu.com'>AA</a>
<a href=' http://www.google.com'>BB</a>
<a href=' http://www.hao123.com'>CC</a>
<a href=' http://www.126.com'>AA</a>这里有四个a标签,标签的显示名有 AA,BB,CC,AA
我想要提取标签显示名为 AA 的,怎样提取啊?在PHP里正则表达式如何写?谢谢正确结果是:http://www.baidu.com和http://www.126.com
<a href=' http://www.baidu.com'>AA</a>
<a href=' http://www.google.com'>BB</a>
<a href=' http://www.hao123.com'>CC</a>
<a href=' http://www.126.com'>AA</a>这里有四个a标签,标签的显示名有 AA,BB,CC,AA
我想要提取标签显示名为 AA 的,怎样提取啊?在PHP里正则表达式如何写?谢谢正确结果是:http://www.baidu.com和http://www.126.com
<a href=' http://www.baidu.com'>AA </a>
<a href=' http://www.google.com'>BB </a>
<a href=' http://www.hao123.com'>CC </a>
<a href=' http://www.126.com'>AA </a>
STR;
preg_match_all("/<a[^<>]*href='([^']+)'[^<>]*>AA[\s]+<\/a>/im", $str, $matches);
var_dump($matches[1]);
<a href=' http://www.google.com'>BB </a>
<a href=' http://www.hao123.com'>CC </a>
<a href=' http://www.126.com'>AA </a> ";$pattern = '@<a(.*?)>(.[^>]*?)</a>@im';preg_match_all($pattern,$subject,$matches);
print_r($matches[0]);
$subject = "<a href=' http://www.baidu.com'>AA</a>
<a href=' http://www.google.com'>BB</a>
<a href=' http://www.hao123.com'>CC</a>
<a href=' http://www.126.com'>AA</a> ";$pattern = '@<a(.*?)>(.[^>]*?)</a>@im';preg_match_all($pattern,$subject,$matches);
foreach($matches[2] as $_key => $_value){
if($_value == 'AA') echo $matches[1][$_key].'</br>';
}
<a href=' http://www.google.com'>BB </a>
<a href=' http://www.hao123.com'>CC </a>
<a href=' http://www.126.com'>AA </a> ";$pattern = '@<a(.*?)>AA[\s]+</a>@im';preg_match_all($pattern,$subject,$matches);echo '<pre>';
print_r($matches[1]);
echo '</pre>';
<a href=' http://www.baidu.com'>AA </a>
<a href=' http://www.google.com'>BB </a>
<a href=' http://www.hao123.com'>CC </a>
<a href=' http://www.126.com'>AA </a>
STR;
preg_match_all("/<a[^<>]*href=['\"]([^'\"]+)['\"][^<>]*>AA[\s]+<\/a>/im", $str, $matches);
var_dump($matches[1]);
<a href=' http://www.google.com'>BB </a>
<a href=' http://www.hao123.com'>CC </a>
<a href=' http://www.126.com' sdf=sdfsd >AA </a> ";$pattern = "@<a[^<>]*href=['\"]?([^'\"]+)['\"]?[^<>]*>AA[\s]+</a>@im";preg_match_all($pattern,$subject,$matches);echo '<pre>';
print_r($matches[1]);
echo '</pre>';