Skip to content

Instantly share code, notes, and snippets.

@vasilii-b
Created April 3, 2025 10:56
Show Gist options
  • Save vasilii-b/4553a20b94a1a2a2878d3c679ed137a0 to your computer and use it in GitHub Desktop.
Save vasilii-b/4553a20b94a1a2a2878d3c679ed137a0 to your computer and use it in GitHub Desktop.
extract youtube code from URL - PHP
$youTubeUrl = "https://www.youtube.com/embed/ARwGpBTQ3sw?si=FgLPCSCYKF1JiVag";
preg_match('/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/', $youTubeUrl, $matches);
$youTubeCode = $matches[1] ?? null;
var_dump(new DateTime());
var_dump($youTubeCode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment