Created
May 29, 2013 02:28
-
-
Save rbk/5667589 to your computer and use it in GitHub Desktop.
PHP function that turns vimeo and youtube urls in to videos.
This file contains hidden or 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 filter_video_links( $content ){ | |
// Regular Expressions | |
$youtube_link = '@^\s*https?://(?:www\.)?(?:youtube.com/watch\?|youtu.be/)([^\s"]+)\s*$@im'; | |
$vimeo_link = '@^\s*https?://(?:www\.)?(?:vimeo.com/)@im'; | |
if( preg_match( $vimeo_link, $content ) ) { | |
// vimeo | |
$content = preg_replace( $vimeo_link, 'http://player.vimeo.com/video/', $content ); | |
return $content; | |
} else if ( preg_match( $youtube_link, $content ) ) { | |
// youtube | |
$content = str_replace( 'http://www.youtube.com/watch?v=', 'http://www.youtube.com/embed/', $content ); | |
return $content; | |
} else { | |
return $content; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment