3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $videoURLs = array( 'http://www.youtube.com/embed/VIDEO_ID', 'http://www.youtube.com/embed/VIDEO_ID/', 'http://youtu.be/VIDEO_ID', 'http://youtu.be/VIDEO_ID/', 'http://www.youtube.com/v/VIDEO_ID', 'http://www.youtube.com/watch?v=VIDEO_ID', 'http://www.youtube.com/watch?feature=player_embedded&v=VIDEO_ID' ); foreach ($videoURLs as $urlNow) { $url = parse_url($urlNow); $pathParts = explode('/', parse_url($url['path'])); $videoID = end($pathParts); if (isset($url['query'])) { parse_str($url['query'], $query); $videoID = (isset($query['v'])) ? $query['v'] : $videoID; } var_dump($urlNow, $videoID, dirname($url['path'])); } ?>
Output for 5.3.1 - 5.6.28, 7.0.0 - 7.1.0
Warning: explode() expects parameter 2 to be string, array given in /in/G1sXJ on line 14 Warning: end() expects parameter 1 to be array, null given in /in/G1sXJ on line 15 string(37) "http://www.youtube.com/embed/VIDEO_ID" NULL string(6) "/embed" Warning: explode() expects parameter 2 to be string, array given in /in/G1sXJ on line 14 Warning: end() expects parameter 1 to be array, null given in /in/G1sXJ on line 15 string(38) "http://www.youtube.com/embed/VIDEO_ID/" NULL string(6) "/embed" Warning: explode() expects parameter 2 to be string, array given in /in/G1sXJ on line 14 Warning: end() expects parameter 1 to be array, null given in /in/G1sXJ on line 15 string(24) "http://youtu.be/VIDEO_ID" NULL string(1) "/" Warning: explode() expects parameter 2 to be string, array given in /in/G1sXJ on line 14 Warning: end() expects parameter 1 to be array, null given in /in/G1sXJ on line 15 string(25) "http://youtu.be/VIDEO_ID/" NULL string(1) "/" Warning: explode() expects parameter 2 to be string, array given in /in/G1sXJ on line 14 Warning: end() expects parameter 1 to be array, null given in /in/G1sXJ on line 15 string(33) "http://www.youtube.com/v/VIDEO_ID" NULL string(2) "/v" Warning: explode() expects parameter 2 to be string, array given in /in/G1sXJ on line 14 Warning: end() expects parameter 1 to be array, null given in /in/G1sXJ on line 15 string(39) "http://www.youtube.com/watch?v=VIDEO_ID" string(8) "VIDEO_ID" string(1) "/" Warning: explode() expects parameter 2 to be string, array given in /in/G1sXJ on line 14 Warning: end() expects parameter 1 to be array, null given in /in/G1sXJ on line 15 string(63) "http://www.youtube.com/watch?feature=player_embedded&v=VIDEO_ID" string(8) "VIDEO_ID" string(1) "/"
Output for hhvm-3.10.0 - 3.12.0
Warning: explode() expects parameter 2 to be string, array given in /in/G1sXJ on line 14 Warning: Invalid operand type was used: expecting an array in /in/G1sXJ on line 15 string(37) "http://www.youtube.com/embed/VIDEO_ID" bool(false) string(6) "/embed" Warning: explode() expects parameter 2 to be string, array given in /in/G1sXJ on line 14 Warning: Invalid operand type was used: expecting an array in /in/G1sXJ on line 15 string(38) "http://www.youtube.com/embed/VIDEO_ID/" bool(false) string(6) "/embed" Warning: explode() expects parameter 2 to be string, array given in /in/G1sXJ on line 14 Warning: Invalid operand type was used: expecting an array in /in/G1sXJ on line 15 string(24) "http://youtu.be/VIDEO_ID" bool(false) string(1) "/" Warning: explode() expects parameter 2 to be string, array given in /in/G1sXJ on line 14 Warning: Invalid operand type was used: expecting an array in /in/G1sXJ on line 15 string(25) "http://youtu.be/VIDEO_ID/" bool(false) string(1) "/" Warning: explode() expects parameter 2 to be string, array given in /in/G1sXJ on line 14 Warning: Invalid operand type was used: expecting an array in /in/G1sXJ on line 15 string(33) "http://www.youtube.com/v/VIDEO_ID" bool(false) string(2) "/v" Warning: explode() expects parameter 2 to be string, array given in /in/G1sXJ on line 14 Warning: Invalid operand type was used: expecting an array in /in/G1sXJ on line 15 string(39) "http://www.youtube.com/watch?v=VIDEO_ID" string(8) "VIDEO_ID" string(1) "/" Warning: explode() expects parameter 2 to be string, array given in /in/G1sXJ on line 14 Warning: Invalid operand type was used: expecting an array in /in/G1sXJ on line 15 string(63) "http://www.youtube.com/watch?feature=player_embedded&v=VIDEO_ID" string(8) "VIDEO_ID" string(1) "/"
Output for 4.3.0 - 5.3.0
Notice: Array to string conversion in /in/G1sXJ on line 14 string(37) "http://www.youtube.com/embed/VIDEO_ID" string(5) "Array" string(6) "/embed" Notice: Array to string conversion in /in/G1sXJ on line 14 string(38) "http://www.youtube.com/embed/VIDEO_ID/" string(5) "Array" string(6) "/embed" Notice: Array to string conversion in /in/G1sXJ on line 14 string(24) "http://youtu.be/VIDEO_ID" string(5) "Array" string(1) "/" Notice: Array to string conversion in /in/G1sXJ on line 14 string(25) "http://youtu.be/VIDEO_ID/" string(5) "Array" string(1) "/" Notice: Array to string conversion in /in/G1sXJ on line 14 string(33) "http://www.youtube.com/v/VIDEO_ID" string(5) "Array" string(2) "/v" Notice: Array to string conversion in /in/G1sXJ on line 14 string(39) "http://www.youtube.com/watch?v=VIDEO_ID" string(8) "VIDEO_ID" string(1) "/" Notice: Array to string conversion in /in/G1sXJ on line 14 string(63) "http://www.youtube.com/watch?feature=player_embedded&v=VIDEO_ID" string(8) "VIDEO_ID" string(1) "/"