Skip to content

Instantly share code, notes, and snippets.

@yusufhm
Last active December 29, 2017 17:38
Show Gist options
  • Save yusufhm/5c84ffe3557f9cbda4eb8cb8bd156206 to your computer and use it in GitHub Desktop.
Save yusufhm/5c84ffe3557f9cbda4eb8cb8bd156206 to your computer and use it in GitHub Desktop.
php regex
<?php
// YouTube id from url.
// @see http://stackoverflow.com/a/6382259/351590
if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match)) {
$video_id = $match[2];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment