Skip to content

Instantly share code, notes, and snippets.

@mustafauysal
Created August 20, 2013 12:17
Show Gist options
  • Select an option

  • Save mustafauysal/6280651 to your computer and use it in GitHub Desktop.

Select an option

Save mustafauysal/6280651 to your computer and use it in GitHub Desktop.
regex youtube id
<?php
$url = "http://www.youtube.com/watch?v=hLQl3WQQoQ0";
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $url, $matches);
echo $matches[1];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment