0

I'm using HTML Purifier and saw a naming conflict with my existing code. The variable $config (an array) is already in use in my code for my config.ini file but based on the HTML Purifier docs, it's also using $config (as object) for customization. Is there a way to rename the $config used by HTML Purifier to something like $htmlpur_config?

2 Answers 2

0

When you create your configuration object just name it differently

<?php
    require_once '/path/to/htmlpurifier/library/HTMLPurifier.auto.php';

    $htmlpur_config = HTMLPurifier_Config::createDefault();
    $htmlpur_config->set('Core.Encoding', 'ISO-8859-1'); // replace with your encoding
    $htmlpur_config->set('HTML.Doctype', 'HTML 4.01 Transitional'); // replace with your doctype
    $purifier = new HTMLPurifier($htmlpur_config);

    $clean_html = $purifier->purify($dirty_html);
?>

The key is creating the $config object and passing it into the constructor for the HTMLPurifier

2
  • Thanks for adding sample code @danielrsmith. I can honestly say that my question is idiotic to say at the very least. Haha
    – enchance
    Dec 29, 2011 at 3:00
  • Don't be sorry, their documentation was a bit confusing if you don't read the entire thing. Dec 29, 2011 at 3:02
0

Just use a different variable:

// Instead of
$config = HTMLPurifier_Config::createDefault();

// Use
$htmlpurifier_config = HTMLPurifier_Config::createDefault();
$htmlpurifier_config->set('some.setting', 'somevalue');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.