how to get Video id from iframe of youtube in php or cakephp

早过忘川 提交于 2019-12-06 13:45:29

问题


i have this iframe

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

how to get video id from it by regular expression or any.....


回答1:


You can use:

$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 will contain:

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


来源:https://stackoverflow.com/questions/6449497/how-to-get-video-id-from-iframe-of-youtube-in-php-or-cakephp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!