如何使用PHP从数组中的所有锚标记获取国家/地区、链接、文本
$str ='
<div class="main">
<span country="PK"></span><a class="link" href="linkOne">1</a>
<span country="US"></span><a class="link" href="linkTwo">2</a>
<span country="UA"></span><a class="link" href="LinkThree">3</a>
</div>';
function getStr($str,$start,$end){
$str = explode($start,$str,2);
$str = explode($end,$str[1],2);
return $str[0];
}
$html = getStr($str,'<div class="main">','</div>');
preg_match_all('/<a[^>]+href=([\'"])(?<href>.+?)\1[^>]*>/i', $html, $result);
if (!empty($result)) {
echo $result['href'][0];
}
需要这样:
/* Array */
$links[0] = "PK", "linkOne", "1";
$links[1] = "US", "linkTwo", "2";
/* and so on ... */
犯罪嫌疑人X