In questo tutorial creeremo una funzione in grado di restituire una thumbnail di un video di youtube.
Il funzionamento è molto semplice, è necessario estrarre l’ID (in formato alfanumerico) ed aggiungerlo a “http://img.youtube.com/vi/IDALFANUMERICO.0.jpg”.
function youtube_video_thumbnail($url,$index=0){ if(preg_match('/^[^v]+v.(.{11}).*/',$url,$matches)){ //url video return 'http://img.youtube.com/vi/'.$matches[1].'/'.$index.'.jpg'; }elseif(preg_match('/youtube.com\/user\/(.*)\/(.*)$/',$url,$matches)){ //url video visualizzato dal canale return 'http://img.youtube.com/vi/'.$matches[2].'/'.$index.'.jpg'; }else{ return false; } }