-3

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

1 回答 1

2

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

foreach($match as $val)
于 2013-08-31T16:44:34.453 回答