Created
June 2, 2021 18:54
-
-
Save chriswagoner/486e932691d8d2c2cd5f64f216538216 to your computer and use it in GitHub Desktop.
Convert YouTube URLs to Embed URLs
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
function go_convert_youtube_url_to_embed_url($youtube_url) { | |
$matches = array(); | |
preg_match('/((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?/', $youtube_url, $matches); | |
return "https://www.youtube.com/embed/".$matches[5]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment