Skip to content

Instantly share code, notes, and snippets.

@clouddueling
Created October 6, 2013 03:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clouddueling/6849208 to your computer and use it in GitHub Desktop.
Save clouddueling/6849208 to your computer and use it in GitHub Desktop.
allow vimeo and youtube iframes in HTMLPurifier
/**
* Sanitize string input
* @param string $dirty_html
* @return string
*/
public static function purify( $dirty_html )
{
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.SafeIframe', true);
$config->set('URI.SafeIframeRegexp', '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%'); //allow YouTube and Vimeo
$purifier = new HTMLPurifier($config);
$clean_html = $purifier->purify($dirty_html);
return $clean_html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment