我有一个包含html代码的字符串。它有很多url格式。我使用preg_match_all来获取所有的url。现在我想循环遍历$match2数组,只打印在完整url中某个位置有".m3u8"的url。var_dump($match2)正确地打印了所有url,但我的for循环一直给我这个错误;
E_NOTICE : type 8 -- Array to string conversion
有人能帮我解决这个问题吗?提前谢谢。
php代码:
$regex2 = "/'b(?:(?:https?|ftp):'/'/|www'.)[-a-z0-9+&@#'/%?=~_|!:,.;]*[-a-z0-9+&@#'/%=~_|]/i";
preg_match_all($regex2,$code,$match2);
var_dump($match2);
for($i = 0; $i < count($match2); $i++){
if (strpos($match2[$i],'.m3u8') !== false) {
echo "<br>".$match2[$i];
} else {
//do nothing
}
}
我将$match2更改为$match2[0],结果出错了!