3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $pattern = '~(?:http|https|)(?::\/\/|)(?:www.|)(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/ytscreeningroom\?v=|\/feeds\/api\/videos\/|\/user\S*[^\w\-\s]|\S*[^\w\-\s]))([\w\-]{11})[a-z0-9;:@?&%=+\/\$_.-]*~i'; $youtube_url = array( "https://youtu.be/yVpbFMhOAwE", "https://www.youtube.com/embed/yVpbFMhOAwE", "youtu.be/yVpbFMhOAwE", "youtube.com/watch?v=yVpbFMhOAwE", "http://youtu.be/yVpbFMhOAwE", "http://www.youtube.com/embed/yVpbFMhOAwE", "http://www.youtube.com/watch?v=yVpbFMhOAwE", "http://www.youtube.com/watch?v=yVpbFMhOAwE&feature=g-vrec", "http://www.youtube.com/watch?v=yVpbFMhOAwE&feature=player_embedded", "http://www.youtube.com/v/yVpbFMhOAwE?fs=1&hl=en_US", "http://www.youtube.com/ytscreeningroom?v=yVpbFMhOAwE", "http://www.youtube.com/watch?NR=1&feature=endscreen&v=yVpbFMhOAwE", "http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo", "http://www.youtube.com/watch?v=6zUVS4kJtrA&feature=c4-overview-vl&list=PLbzoR-pLrL6qucl8-lOnzvhFc2UM1tcZA", ); foreach($youtube_url as $youtube_url) { $youtube_id = (preg_replace($pattern, '$1', $youtube_url)); var_dump ($youtube_id); }
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
string(11) "yVpbFMhOAwE" string(11) "yVpbFMhOAwE" string(11) "yVpbFMhOAwE" string(11) "yVpbFMhOAwE" string(11) "yVpbFMhOAwE" string(11) "yVpbFMhOAwE" string(11) "yVpbFMhOAwE" string(11) "yVpbFMhOAwE" string(11) "yVpbFMhOAwE" string(11) "yVpbFMhOAwE" string(11) "yVpbFMhOAwE" string(11) "yVpbFMhOAwE" string(11) "1p3vcRhsYGo" string(11) "6zUVS4kJtrA"