3v4l.org

run code in 300+ PHP versions simultaneously
<?php function um_youtube_id_from_url($url) { $pattern = '%^# Match any youtube URL (?:https?://)? # Optional scheme. Either http or https (?:www\.)? # Optional www subdomain (?: # Group host alternatives youtu\.be/ # Either youtu.be, | youtube\.com # or youtube.com (?: # Group path alternatives /embed/ # Either /embed/ | /v/ # or /v/ | /watch\?v= # or /watch\?v= ) # End path alternatives. ) # End host alternatives. ([\w-]{10,12}) # Allow 10-12 for 11 char youtube id. $%x' ; $result = preg_match($pattern, $url, $matches); if (false !== $result) { return $matches[1]; } return false; } var_dump(um_youtube_id_from_url('<a href="https://www.youtube.com/watch?v=1aaXl4vaeJU">https://www.youtube.com/watch?v=1aaXl4vaeJU</a>')); var_dump(um_youtube_id_from_url("https://www.youtube.com/watch?v=1aaXl4vaeJU")); var_dump(um_youtube_id_from_url("https://www.youtube.com/v/1aaXl4vaeJU"));
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined array key 1 in /in/tKOvA on line 21 NULL string(11) "1aaXl4vaeJU" string(11) "1aaXl4vaeJU"
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Undefined array key 1 in /in/tKOvA on line 21 NULL string(11) "1aaXl4vaeJU" string(11) "1aaXl4vaeJU"
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined offset: 1 in /in/tKOvA on line 21 NULL string(11) "1aaXl4vaeJU" string(11) "1aaXl4vaeJU"
Output for 7.3.32 - 7.3.33
NULL string(11) "1aaXl4vaeJU" string(11) "1aaXl4vaeJU"

preferences:
170.14 ms | 401 KiB | 188 Q