php mysqli tutorial | dyanamik xml sitemap | apt-get ups | create sitemap from database php


How to Start Youtube Playlist from Random Video

If you want to start a Youtube playlist from random video, just add: &index=random_number to the src attribute of the embed code.

The code

To produce a random number, I use php rand. Something like

	print rand(1,9)

(replace "9" with the count of your playlist videos).


Here is an example of embed code:

<iframe width="853"
		src="//<?php print rand(1,9)?>"


Refresh the page to see the result.

Sign-up for our free email newsletter. Get updates when new tutorials and tips are published. You can unsubscribe anytime with a click.

Your comments are welcomed!

This site actively encourages commenting on any post. Comments are not pre-moderated, but this community does not tolerate direct or indirect attacks, name-calling or insults. Please, read terms of use and Comment Policy at privacy policy.

More tips