【问题标题】:how to get Video id from iframe of youtube in php or cakephp如何在 php 或 cakephp 中从 youtube 的 iframe 获取视频 ID
【发布时间】:2011-06-23 04:56:27
【问题描述】:

我有这个 iframe

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

如何通过正则表达式或任何方式从中获取视频ID.....

【问题讨论】:

    标签: php cakephp cakephp-1.3


    【解决方案1】:

    你可以使用:

    $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 )
    

    【讨论】:

    • 我对语法高亮不满意。这可以改进吗?
    猜你喜欢
    • 1970-01-01
    • 2016-09-28
    • 2021-02-10
    • 1970-01-01
    • 2012-04-15
    • 2020-11-05
    • 1970-01-01
    • 2011-03-24
    • 2012-05-22
    相关资源
    最近更新 更多