Skip to content Skip to sidebar Skip to footer

Htmlpurifier - Adding To Ignore List

I am trying to pass some XML tags (abcdef>) through htmlpurifier. Since the tags itself are not supported, I am trying to add an element first and then adding it to allowedEleme

Solution 1:

You should turn on error reporting; makes dev a lot easier!

ini_set('display_errors', true);
error_reporting(E_ALL & ~E_NOTICE); // or E_ALL if you're feeling good

Fixing a bunch of errors (the "cannot edit configuration after finalization means all your configs need to be before you getHTMLDefinition; deprecated API means that you should change your config set format but is harmless), then you get a blank string. Then you need to make sure your new elements are in the allowed elements of someone else, an easy way to do this is mark them Inline. I doubt the AllowedElements attribute is what you want, because it will exclude all other elements...

<?phprequire_once'library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('Core.Encoding', "UTF-8");
$config->set('HTML.DefinitionID', 'pinaki-test');
$config->set('HTML.DefinitionRev', 3);
$config->set('Cache.DefinitionImpl', null); // remove this later!$config->set('Cache.SerializerPath', "/var/cache/htmlpurify");
$config->set('HTML.AllowedElements', array("tag1", "tag2"));
$def = $config->getHTMLDefinition(true);
$def->addElement("tag1", 'Inline', 'Empty', 'Common', array());
$def->addElement("tag2", 'Inline', 'Empty', 'Common', array());
$purifier = new HTMLPurifier($config);
echo$purifier->purify('<tag1>asf');

Post a Comment for "Htmlpurifier - Adding To Ignore List"