3v4l.org

run code in 500+ PHP versions simultaneously
<?php function check_link($link) { if(preg_match('#v=\K[a-z\d-]+|v/\K[^&?"]+|v=\K[^&"]+|youtu\.be/\K[^&"]+#', $link, $r)) { echo $r[0]."\n"; $pattern = '#<a\s?href="(https?://(?:www\.)?[^"]+)">\1</a>#i'; return preg_replace($pattern,'<iframe width="560" height="315" src="https://www.youtube.com/embed/'.$r[0].'" frameborder="0"></iframe>',$link); } } echo check_link('<a href="https://www.youtube.com/watch?v=Z7Oc8QaM5VU">https://www.youtube.com/watch?v=Z7Oc8QaM5VU</a>');
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Z7Oc8QaM5VU <iframe width="560" height="315" src="https://www.youtube.com/embed/Z7Oc8QaM5VU" frameborder="0"></iframe>

preferences:
97.78 ms | 1420 KiB | 4 Q