如何在 preg_match_all 匹配数组中查找字符串模式?

How to find a string pattern in preg_match_all match array?

我有一个带有 html 代码的字符串。它有很多 urls 格式。我用 preg_match_all 得到了所有的 url。现在我想循环遍历 $match2 数组,只打印 url 中包含“.m3u8”的 url 的完整 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 更改为 $match 2[0] 并且成功了!