Preg匹配文本php不起作用


Preg match text php dont work

你好,我想使用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()

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

foreach($match as $val)