如何在php或cakephp中从youtube的iframe获取视频ID

时间:2011-06-23 04:56:28

标签: php cakephp cakephp-1.3

我有这个iframe

<iframe width="425" height="349" src="http://www.youtube.com/embed/YRUG-Pu7RzE" frameborder="0" allowfullscreen></iframe>

如何通过正则表达式或任何.....

从中获取视频ID

1 个答案:

答案 0 :(得分:0)

您可以使用:

$subject = '<iframe width=\"425\" height=\"349\" src=\"http://www.youtube.com/embed/YRUG-Pu7RzE\" frameborder=\"0\" allowfullscreen></iframe>';
$pattern = '!http://(?:www.)?youtube.com/embed/([^"']+)!i';
$result = preg_match($pattern, $subject, $subpattern); 

$ subpattern将包含:

Array ( [0] => http://www.youtube.com/embed/YRUG-Pu7RzE [1] => YRUG-Pu7RzE )