Given a YouTube Video URL can you find the VID from the URL?.The following Phip snippet helps you to do the same. The key things to keep in mind that VID which is a unique string for any video is 11 characters in length. Also the VID is represented by a v parameter in the URL.
An example of YouTube view URL can be
http://www.youtube.com/watch?v=Ig6c3P4ODC4
or
http://www.youtube.com/watch?feature=player_embedded&v=Ig6c3P4ODC4
In other words the v parameter can be any where in the URL.
<!--break-->
- function getYoutubeVideoId($url){
- // len of video id
- $vidlen=11;
- // Search for the v paramter in the url "youtube.com/watch?v=" in the URL
- $index=strpos($url,"?v=");
- // if not found, search with an &v
- if($index===FALSE){
- $index=strpos($url,"&v=");
- }
- // not found
- if($index===FALSE){
- // cannot find it
- return"";
- }
- # offset 3 chars to position to the begin
- $index=$index+3;
- // Substring and find the vid
- $vid=substr($url,$index,$vidlen);
- return$vid;
- }