I have the following code that grabs youtube’s video id from the old share urls (youtube.com/watch?v=adasdalkjsd)
$url = $_GET['url'];
parse_str(parse_url($url, PHP_URL_QUERY), $query);
$video_id = isset($query['v']) ? $query['v'] : NULL;
that works for the old ones but i need a system that can work for both urls. any suggestions?
The URLs are for example: http://youtu.be/QzEcJecXJC4?hd=1
See parse_url. PHP_URL_PATH will give you
/QzEcJecXJC4, so you need to usesubstrto cut out the slash.