I want to get the individual ID from a youtube link so that I can use it later on, to pull other information such as its thumbnail image and insert it into the embedded iframe.
I notice there that all, I hope, of the urls on youtube start http://www.youtube.com/watch?v=
Unique video ID and then depending on a few things can end something like &list=RD02M5u5zXVmoHM
. But the unique id always has a &
after it and the watch?v=
before. Is this the best way to do it? Have a written this correctly?
$link=$_POST['link'];
$link_id=str_replace('http://www.youtube.com/watch?v=', '', $link);
$link_id=strstr($link_id, '&', true);
This comes from form data. Is there anything other variables from youtube URLs I may encounter?