PHP Classes

HTML Sanitizer: Remove unsafe tags and attributes from HTML code

Recommend this page to a friend!

  Author Author  
Picture of Frédéric Minne
Name: Frédéric Minne <contact>
Classes: 2 packages by
Country: Belgium Belgium
Age: 42
All time rank: 5591 in Belgium Belgium
Week rank: 845 Down6 in Belgium Belgium Down

  Detailed description   Download Download .zip .tar.gz   Install with Composer Install with Composer  
This class can be used to remove unsafe tags and attributes from HTML code.

It takes a string with HTML code and strips all the tags that do not make part of a list of safe tags. That list of safe tags is defined as a private class variable. There are some functions to allow usually unsafe tags like script, style, object, embed, etc..

The class can also remove unsafe tag attributes, such as those that define Javascript code to handle events.

The links href attributes also gets special treatment to remove URLs that trigger Javascript code execution and line breaks.


HTML Sanitizer

Simple lightweight HTML sanitizer class for PHP

Copyright notice

(see COPYING for more details)

Copyright (c) 2005-2013 Frederic Minne <>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU LESSER General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

  Classes of Frédéric Minne  >  HTML Sanitizer  >  Download Download .zip .tar.gz  >  Support forum Support forum (3)  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: HTML Sanitizer
Base name: htmlsanitizer
Description: Remove unsafe tags and attributes from HTML code
Version: 1.3
PHP version: 5.2
License: GNU General Public License (GPL)
All time users: 3394 users
All time rank: 1006
Week users: 0 users
Week rank: 177 Equal
  Groups   Rate classes User ratings   Trackback   Applications   Files Files  

Group folder image HTML HTML generation and processing View top rated classes
Group folder image Security Security protection and attack detection View top rated classes

  User ratings  
RatingsUtility Consistency Documentation Examples Tests Videos Overall Rank
All time: Good (90%) Good (90%) - Sufficient (78%) - - Sufficient (62%) 1150
Month: Not yet rated by the users

  Pages that reference this package  
PHP SQL Injection and XSS detection program
PHP Security
PHP code security and XSS, SQL injection and other types of sites for the safety of a very used, in particular, UGC (User Generated Content) sites, forums and e-commerce sites, often XSS and SQL injection is the hardest hit...
PHP SQL Injection and XSS detection program

Latest pages that reference packages Latest pages that reference packages

  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
File Role Description
Accessible without login Plain text file COPYING Lic. GNU LGPL
Accessible without login Plain text file helpers.lib.php Aux. Auxiliary script
Plain text file HTML_Sanitizer.php Class Class source
Accessible without login Plain text file Doc. Documentation
Accessible without login Plain text file sample.php Example Example

Install with Composer Install with Composer - Download Download all files: htmlsanitizer.tar.gz
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
For more information send a message to info at phpclasses dot org.