Created
May 27, 2020 12:51
-
-
Save zecka/911ee29f30d7b2f85b84f9dc2b13c377 to your computer and use it in GitHub Desktop.
Example use of HTMLPurifier PHP
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 | |
// composer install ezyang/htmlpurifier | |
require 'vendor/autoload.php'; | |
$config = HTMLPurifier_Config::createDefault(); | |
$config->set('HTML.AllowedElements', 'a,i,b,p,div,strong,h1,h2,h3,h4,h5,ol,ul,li,br'); | |
$config->set('HTML.AllowedAttributes', 'href,title,target,name'); | |
$config->set('HTML.Attr.Name.UseCDATA', true); | |
$config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true); | |
$config->set('Attr.AllowedFrameTargets', ['_blank']); | |
$config->set('AutoFormat.RemoveEmpty', true); | |
$purifier = new HTMLPurifier($config); | |
$clean_html = $purifier->purify($content); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment