Skip to content

Instantly share code, notes, and snippets.

@talkahe
Last active October 26, 2017 20:41
Show Gist options
  • Save talkahe/31f9ec351a9d874a1993211464e35045 to your computer and use it in GitHub Desktop.
Save talkahe/31f9ec351a9d874a1993211464e35045 to your computer and use it in GitHub Desktop.
Expresión regular ID video Youtube
<?php
//obetener la id del video de youtube
$url = $_POST["video"];
preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $url, $matches);
$video = $matches[0];
if($video==""){
echo "La URL debe ser un enlace a Youtube.";
die();
}else{
echo "OK.";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment