PHP从iframe / object嵌入数组中提取youtube视频ID?

我有一组youtube iframes / objects如下:

[0] => <iframe width="600" height="338" src="http://www.youtube.com/embed/szL_PVuzWp0?fs=1&feature=oembed" frameborder="0" allowfullscreen></iframe>
[1] => <object width="600" height="338"><param name="movie" value="http://www.youtube.com/v/jm1S43a-e3Y?version=3&feature=oembed"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/jm1S43a-e3Y?version=3&feature=oembed" type="application/x-shockwave-flash" width="600" height="338" allowscriptaccess="always" allowfullscreen="true"></embed></object>
[2] => <iframe width="600" height="338" src="http://www.youtube.com/embed/7fTploFSbXA?fs=1&feature=oembed" frameborder="0" allowfullscreen></iframe>
[3] => <iframe width="600" height="338" src="http://www.youtube.com/embed/vQSRNYgiuMk?fs=1&feature=oembed" frameborder="0" allowfullscreen></iframe>

注意,嵌入方法可以变化(通常< iframe>,偶尔< object>)(由于外部数据源).

我如何/为每个提取视频URL(例如vQSRNYgiuMk或jm1S43a-e3Y)的最可靠方法是什么?

最终我想最终得到一个像这样的数组:

[0] => "szL_PVuzWp0"
[1] => "jm1S43a-e3Y"
[2] => "7fTploFSbXA"
[3] => "vQSRNYgiuMk"

解决方法:

foreach($arr as $i=>$a){
    $start = strpos($a, "/v/") + 3;
    if(!$start) $start = strpos($a, "/embed/") + 7;
    $qm = strpos("?");
    $length = $qm - $start;
    $new_array[$i] = substr($a, $start, $length);
}
上一篇:python-在临时存储器中访问用户上传的视频时出现问题


下一篇:php – 使用公司代理的后备解决方案嵌入YouTube视频