开发者

fetching youtube playlist id with php regex

开发者 https://www.devze.com 2023-02-13 14:24 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消