3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function _getYoutubeVideoId($url) { $parts = parse_url($url); //For seriously malformed urls if ($parts === false) { return false; } switch ($parts['host']) { case 'youtu.be': return substr($parts['path'], 1); break; case 'youtube.com': case 'www.youtube.com': parse_str($parts['query'], $params); return $params['v']; break; default: return false; break; } } var_dump(_getYoutubeVideoId("www.youtube.com/watch?v=WQq0RAbj4i8"));
based on 7qUg6
Output for 5.3.0 - 7.1.0
Notice: Undefined index: host in /in/bSRP6 on line 12 bool(false)
Output for 4.3.0 - 5.2.17
Notice: Undefined index: host in /in/bSRP6 on line 12 bool(false)