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 6701405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:55:50+00:00 2026-05-26T06:55:50+00:00

I am just looking into using HTML Purifier to ensure that a user-inputed string

  • 0

I am just looking into using HTML Purifier to ensure that a user-inputed string (that represents the name of a person) is sanitized.

I do not want to allow any html tags, script, markup etc – I just want the alpha, numeric and normal punctuation characters.

The sheer number of options available for HTML Purifier is daunting and, as far as i can see, the docs do not seem to have a beggining/middle or end

see: http://htmlpurifier.org/docs

Is there a simple hello world tutorial online for HTML Purifier that shows how to sanitize a string removing all the bad stuff out of it.

I am also considering just using strip tags:

  • http://php.net/manual/en/function.strip-tags.php

or PHP’s in built data sanitizing

  • http://us.php.net/manual/en/book.filter.php
  • 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-26T06:55:50+00:00Added an answer on May 26, 2026 at 6:55 am

    I’ve been using HTMLPurifier for sanitizing the output of a rich text editor, and ended up with:

    include_once('htmlpurifier/library/HTMLPurifier.auto.php');
    
    $config = HTMLPurifier_Config::createDefault();
    $config->set('Core', 'Encoding', 'UTF-8');
    $config->set('HTML', 'Doctype', 'HTML 4.01 Transitional');
    
    if (defined('PURIFIER_CACHE')) {
        $config->set('Cache', 'SerializerPath', PURIFIER_CACHE);
    } else {
        # Disable the cache entirely
        $config->set('Cache', 'DefinitionImpl', null);
    }
    
    # Help out the Purifier a bit, until it develops this functionality
    while (($cleaner = preg_replace('!<(em|strong)>(\s*)</\1>!', '$2', $input)) != $input) {
        $input = $cleaner;
    }
    
    $filter = new HTMLPurifier($config);
    $output = $filter->purify($input);
    

    The main points of interest:

    1. Include the autoloader.
    2. Create an instance of HTMLPurifier_Config as $config.
    3. Set configuration settings as needed, with $config->set().
    4. Create an instance of HTMLPurifier, passing $config to it.
    5. Use $filter->purify() on your input.

    However, it’s entirely overkill for something that doesn’t need to allow any HTML in the output.

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

Sidebar

Related Questions

I am looking into writing web based games using just Javascript, HTML, and CSS.
I'm looking for a way to convert HTML entity numbers into a character using
I have just started looking into jquerymobile, done simple samples using jquery.mobile-1.0a1 . I
I just began looking into source control.... And installed subversion from collabnet... I also
I have just been looking into Linq with ASP.Net. It is very neat indeed.
How would you test this scenario? I've just started looking into NHibernate and having
Just some days ago I started looking into a unit test framework called check,
I am just looking at sorting an NSArray of NSNumbers into numeric order but
I was just going to use the FileUpload.FileBytes property but looking into the respective
Just looking for the first step basic solution here that keeps the honest people

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.