Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 712017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:48:04+00:00 2026-05-14T04:48:04+00:00

I’m using HTMLPurifier in a current project and I’m not sure about the most

  • 0

I’m using HTMLPurifier in a current project and I’m not sure about the most efficient way to go about handling multiple configs. For the most part the only major thing changing is the allowed tags.

Currently I have a private method, in each class using HTMLPurifier, that gets called when a config is needed and it creates one from the default. I’m not really happy with this as if 2 classes are using the same config, that’s duplicating code, and what if a class needs 2 configs? It just feels messy.

The one upside to it, is it’s lazy in the sense that it’s not creating anything until it’s needed. The various classes could be used and never have to purify anything. So I don’t want to be creating a bunch of config objects that might not even be used.

I just recently found out that you can create a new instance of HTMLPurifier and directly set config options like so:

$purifier = new HTMLPurifier();
$purifier->config->set('HTML.Allowed', '');

I’m not sure if that’s bad form at all or not, and if it isn’t I’m not really sure of a good way to put it to use.

My latest idea was to create a config handler class that would just return an HTMLPurifier config for use in subsequent purify calls. At some point it could probably be expanded to allow the setting of configs, but just from the start I figured they’d just be hardcoded and run a method parameter through a switch to grab the requested config. Perhaps I could just send the stored purifier instance as an argument and have the method directly set the config on it like shown above?

This to me seems the best of the few ways I thought of, though I’m not sure if such a task warrants me creating a class to handle it, and if so, if I’m handling it in the best way.

I’m not too familiar with the inner workings of HTMLPurifier so I’m not sure if there are any better mechanisms in place for handling multiple configs.

Thanks for any insight anyone can offer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:48:04+00:00Added an answer on May 14, 2026 at 4:48 am

    I just wrote up a quick, simple config handler class.

    You can view / use it @ http://gist.github.com/358187/

    It takes an array of configs at initialization.

    $configs = array(
      'HTML.Doctype' => 'HTML 4.01 Strict',
    
      'posts' => array(
        'HTML.Allowed' => 'p,a[href],img[src]'
      ),
      'comments' => array(
        'HTML.Allowed' => 'p'
      ),
    
      'default' => array(
        'HTML.Allowed' => ''
      )
    );
    

    Directives put directly into the array are global and will be applied to all configs. If the same directive is set inside a named config, the value in the named config will be used.

    Then you can grab a config like so:

    $purifierConfig = new purifierConfig($configs);
    $commentsConfig = $purifierConfig->getConfig('comments');
    

    or, shorthand:

    $commentsConfig = $purifierConfig['comments'];
    

    If the requested config does not exist or no config is specified in the call, the default config will be returned.

    I’ll probably flesh it out at some point, but for now this works.

    I was looking for how people handled such things in their projects or if there were any built in mechanisms that made something like this more steamlined, but I suppose my question was a bit too narrow in scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Creating a relationship doesn't mean you have to load the… May 14, 2026 at 8:18 pm
  • Editorial Team
    Editorial Team added an answer To use an XML Schema with XmlDataDocument, you should only… May 14, 2026 at 8:18 pm
  • Editorial Team
    Editorial Team added an answer One has a descendant selector in the middle of it.… May 14, 2026 at 8:18 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.