Embedding a video into a web page used to be a real challenge in the early days of the web. This small script will help you in embedding youtube videos on your site very easy.

$res = $browser->request('http://www.youtube.com/results?search_query='.urlencode($keys[$i]));
preg_match_all('#<div class="video-entry.*">.*<a.*id="video-long-title-[^"]+".*href="([^"]+)".*title="([^"]+)"#Uuis', $res, $videos);
$src = 'http://www.youtube.com'.$videos['1'][array_rand($videos['1'])];
$src = str_replace(array('?', '='), '/', $src);
$posts[$i]['text'] .= '<object width="425" height="344"><param name="movie" value="'.$src.'&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="wmode" value="transparent"></param><embed src="'.$src.'&fs=1" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>'.'<br/><br/>'."n";
 

Leave a Comment

You must be logged in to post a Review.