Preg_match文本php不起作用

时间:2013-08-31 16:43:08

标签: php preg-match

您好我想使用preg_match 我有它,为什么不工作?

$source = "<span class=\"middle\">".
    "<span class=\"play\"></span>". 
    "<img width=\"114\" src=\"http://i.ytimg.com/vi/PnmEKNi1DtY/default.jpg\" alt=\"\"></span> 1";


preg_match("'<span class=\"middle\"><span class=\"play\"></span> <img width=\"114\" src=\"http://i.ytimg.com/vi/(.*?)/default.jpg\" alt=\"\"></span> 1'si", $source, $match);

  foreach($match[1] as $val)
    {
        echo $val."<br>";


    }

输出:

Warning: Invalid argument supplied for foreach()

1 个答案:

答案 0 :(得分:2)

因为$match[0]是标量,而不是数组。你会用:

foreach($match as $val)