Created
January 11, 2019 10:01
-
-
Save vlepeule/31c95569fa494a739c0707b8a304a350 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function youtubeIdFromIframe( $iframe_string ) { | |
preg_match( '/src="([^"]+)"/', $iframe_string, $match ); | |
$url = $match[1]; | |
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match); | |
$youtube_id = $match[1]; | |
return $youtube_id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment