3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getEmbedUrl($url) { $parseURL = parse_url($url); // YouTube if ($parseURL['host'] === 'youtube.com') { parse_str($parseURL['query'], $query); $code = $query['v']; return "//www.youtube.com/embed/{$code}?rel=0"; } if ($parseURL['host'] === 'youtu.be') { $path = $parseURL['path']; return "//www.youtube.com/embed{$path}?rel=0"; } // Vimeo if ($parseURL['host'] === 'vimeo.com') { $path = $parseURL['path']; return "//player.vimeo.com/video{$path}"; } return str_replace('http://', '//', $uri); } $tests = [ 'https://youtube.com/watch?v=xluE7UQPOJ0' => '//www.youtube.com/embed/xluE7UQPOJ0?rel=0', 'http://youtu.be/nt0spzes2j0' => '//www.youtube.com/embed/nt0spzes2j0?rel=0', 'https://vimeo.com/172016440' => '//player.vimeo.com/video/172016440', ]; foreach($tests as $url => $embed) { $result = getEmbedUrl($url); var_dump($url, $embed, $result, $embed === $result); echo PHP_EOL; }
Output for git.master, git.master_jit, rfc.property-hooks
string(39) "https://youtube.com/watch?v=xluE7UQPOJ0" string(41) "//www.youtube.com/embed/xluE7UQPOJ0?rel=0" string(41) "//www.youtube.com/embed/xluE7UQPOJ0?rel=0" bool(true) string(27) "http://youtu.be/nt0spzes2j0" string(41) "//www.youtube.com/embed/nt0spzes2j0?rel=0" string(41) "//www.youtube.com/embed/nt0spzes2j0?rel=0" bool(true) string(27) "https://vimeo.com/172016440" string(34) "//player.vimeo.com/video/172016440" string(34) "//player.vimeo.com/video/172016440" bool(true)

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
34.16 ms | 402 KiB | 8 Q