<li><a href="/plus/ajax.php?open=2&id=826186" target="_blank">打开</a></li>
源码中有这么一段,我想获取其中的url /plus/ajax.php?open=2&id=826186 php正则怎么获取,新手,望指点一下
源码中有这么一段,我想获取其中的url /plus/ajax.php?open=2&id=826186 php正则怎么获取,新手,望指点一下
$s ='<li><a href="/plus/ajax.php?open=2&id=826186" target="_blank">打开</a></li>';
preg_match_all('/href="(.*?)"/i',$s,$arr);
print_r($arr);只匹配上面给的字符串
if(preg_match_all('/<li><a\s*href="(.*?)"\s*target="_blank">.*?[^<]<\/a><\/li>/is',$s,$match)){
//print_r($match);
$tmp = $match[1][0]; //$tmp 就是你要的部分
//echo $tmp ;
}
//哥也来个兼容性强大点的吧。。preg_match_all('/<a[^>]*href\s*=\s*[\'"]([^\'">]*)[\'"]/i',$string,$matches);var_dump($matches[1]);
preg_match("/<a\shref=\"([^\"]+)\"/",$str,$match);
print_r($match);