I am trying to fetch the playlist id
from url and save it into a new variable.
For instance, if a user inputs this into a form, which then is submitted
http://www.youtube.com/watch?v=A7izsd5IXq8&playnext=1&list=PL6753173C0F0BE9ED
I just want to grab PL6753173C0F0BE9ED
and save it into a new variable. I tried to use explode to do this so it saved everything after the &list=
but I am not having much开发者_如何学Python luck.
Any ideas to do this?
Thanks for the help!
You could use parse_str and parse_url
$string = 'http://www.youtube.com/watch?v=A7izsd5IXq8&playnext=1&list=PL6753173C0F0BE9ED';
$url = parse_url($string);
parse_str($url['query'],$q);
$list = $q['list'];
$url = 'http://www.youtube.com/watch?v=A7izsd5IXq8&playnext=1&list=PL6753173C0F0BE9ED';
$pl = preg_match('/list=(PL[a-f0-9]+)/i', $url, $match)
? $match[1]
: false;
try
$url = 'http://www.youtube.com/watch?v=A7izsd5IXq8&playnext=1&list=PL6753173C0F0BE9ED';
echo end(explode('=', $url));
$url = 'http://www.youtube.com/watch?v=A7izsd5IXq8&playnext=1&list=PL6753173C0F0BE9ED';
echo "URL = $url<br />";
$playlistID = explode("&list=", $url);
echo "playlistID = $playlistID[1]";
this seems to work
精彩评论