Created
April 26, 2017 00:23
-
-
Save davidchc/869210f08ca029d6c5fbf9e1ea3a5885 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 getEmbed($value) | |
{ | |
$video = $value[1]; | |
$output = explode( '?v=', $video); | |
$player = '<iframe src="https://www.youtube.com/embed/%s"></iframe>'; | |
return sprintf($player, $output[1]); | |
} | |
function bbcode($content) | |
{ | |
$pattern = '@\[video\](.*?)\[\/video\]@'; | |
return preg_replace_callback($pattern, "getEmbed", $content); | |
} | |
$string = '[video]https://www.youtube.com/watch?v=YgHRBEYy6mM[/video]'; | |
echo bbcode($string); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment