nigel - 2010-03-12 09:24:27
Sometimes you might what to get thumbnails from the embed code
$input_string = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/M_bvT-DGcWw&hl=en_GB&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/M_bvT-DGcWw&hl=en_GB&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
$count = preg_match('/src=(["\'])(.*?)(["\'])/', $input_string, $match);
if ($count === FALSE) {
echo('not found\n');
}else{
$player = $match[2];
}
$jutjub = new YouTube($player);
Therefore your calls should match either
if (preg_match('/watch\?v\=([A-Za-z0-9_-]+)/', $url, $matches))
return $matches[1];
elseif (preg_match('/v\/([A-Za-z0-9_-]+)/', $url, $matches))
return $matches[1];
else
return false;
Also the "v" presumes that all images are located at this address which is not always the case.