Jump to content

Displaying random YouTube videos ...


AshleyQuick

Recommended Posts

Can someone assist with a code snippet that will randomly display YouTube videos using their embed code?

 

<iframe width="560" height="315" src="//www.youtube.com/embed/bYI_aOyCn9Y" frameborder="0" allowfullscreen></iframe>


 

 

I'd like to cycle through 3-4 videos.

 

Link to comment
https://forums.phpfreaks.com/topic/282172-displaying-random-youtube-videos/
Share on other sites

Random on page load. And yep, a php snippet. I found something similar here:

 

		<?php			$content = array(			    'http://www.address1.com|image1|Caption 1',			    'http://www.address2.com|image2|Caption 2',			    'http://www.address3.com|image3|Caption 3',			    'http://www.address4.com|image4|Caption 4'			);			shuffle($content);			foreach ($content as $value)			{			    $explode = explode('|', $value);			    echo '<p><a href="' . $explode[0] . '"><img src="/misc/php/shuffle/' . $explode[1] . '.gif" border="0" width="100" height="25" align="absmiddle"></a>  <a href="' . $explode[0] . '">' . $explode[2] . '</a></p>';			}			?>

  But I couldn't get that to work with the YouTube code.

Try out with this one...

 

<?php 

$file 
"path/to/text/file.txt"

$data file($file); 
$line trim($data[rand(0,count($data))]); 
echo 
'<object width="425" height="350"><param name="movie" value="http://www.youtube.com/watch?v='.$line.'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/watch?v='.$line.'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>'

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.