PHP Classes

class should match embed or url

Recommend this page to a friend!

      YouTube  >  All threads  >  class should match embed or url  >  (Un) Subscribe thread alerts  
Subject:class should match embed or url
Summary:get thumbnails from the embed code
Messages:1
Author:nigel
Date:2010-03-12 09:24:27
 

  1. class should match embed or url   Reply   Report abuse  
Picture of nigel 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.