Skip to content

Instantly share code, notes, and snippets.

@marcus-at-localhost
Last active December 13, 2021 11:15
Show Gist options
  • Save marcus-at-localhost/a0baec722aefe68cf019bc31f120c3ac to your computer and use it in GitHub Desktop.
Save marcus-at-localhost/a0baec722aefe68cf019bc31f120c3ac to your computer and use it in GitHub Desktop.
[Replace tags with HTML Purifier] http://htmlpurifier.org/ #dom
<?php
// include HTMLPurifier.php
$config = HTMLPurifier_Config::createDefault();
$config->set('AutoFormat.RemoveEmpty', true);
$config->set('AutoFormat.AutoParagraph', true);
$config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
$config->set('CSS.AllowedProperties', array());
$config->set('HTML.ForbiddenAttributes', array('*@class'));
// tag transformation
$def = $config->getHTMLDefinition(true);
$def->info_tag_transform['h2'] = new HTMLPurifier_TagTransform_Simple('strong');
$purifier = new HTMLPurifier($config);
$content = $purifier->purify($content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment