PHP Youtube视频ID正则表达式和PHP功能

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Youtube视频ID正则表达式和PHP功能相关的知识,希望对你有一定的参考价值。

/**
 * Creates a YouTube thumbnail URL from a YouTube video URL
 */
function youtube_video_thumbnail($url,$index=0){
    if(preg_match('/^[^v]+v.(.{11}).*/',$url,$matches)){
        return 'http://img.youtube.com/vi/'.$matches[1].'/'.$index.'.jpg';
    }elseif(preg_match('/youtube.com\/user\/(.*)\/(.*)$/',$url,$matches)){
        return 'http://img.youtube.com/vi/'.$matches[2].'/'.$index.'.jpg';
    }else{
        return false;
    }
}

以上是关于PHP Youtube视频ID正则表达式和PHP功能的主要内容,如果未能解决你的问题,请参考以下文章