Skip to content

Instantly share code, notes, and snippets.

@Toyz
Created December 29, 2015 19:30
Show Gist options
  • Save Toyz/230be37ffae401e4ab5a to your computer and use it in GitHub Desktop.
Save Toyz/230be37ffae401e4ab5a to your computer and use it in GitHub Desktop.
<?php
class YoutubeEmbed extends JBBCode\CodeDefinition {
public function __construct()
{
parent::__construct();
$this->setTagName("youtubeEmbed");
}
public function asHtml(JBBCode\ElementNode $el)
{
$content = "";
foreach($el->getChildren() as $child)
$content .= $child->getAsBBCode();
$foundMatch = preg_match('/v=([A-z0-9=\-]+?)(&.*)?$/i', $content, $matches);
if(!$foundMatch)
return $el->getAsBBCode();
else
return "<iframe width=\"640\" height=\"390\" src=\"http://www.youtube.com/embed/".$matches[1]."\" frameborder=\"0\" allowfullscreen></iframe>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment