PHP Classes

HTML Sanitizer: Remove unsafe tags and attributes from HTML code

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 67%Total: 3,406 All time: 1,006 This week: 74Up
Version License PHP version Categories
htmlsanitizer 1.3GNU General Publi...5.2HTML, Security
Description 

Author

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.

Picture of Frédéric Minne
Name: Frédéric Minne <contact>
Classes: 2 packages by
Country: Belgium Belgium
Age: 45
All time rank: 5621 in Belgium Belgium
Week rank: 178 Up2 in Belgium Belgium Down

Details

HTML Sanitizer

Simple lightweight HTML sanitizer class for PHP

Copyright notice

(see COPYING for more details)


Copyright (c) 2005-2013 Frederic Minne <zefredz@gmail.com>

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
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
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

  Files folder image Files (5)  
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 README.md Doc. Documentation
Accessible without login Plain text file sample.php Example Example

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:3,406
This week:0
All time:1,006
This week:74Up
 User Ratings  
 
 All time
Utility:86%StarStarStarStarStar
Consistency:86%StarStarStarStarStar
Documentation:83%StarStarStarStarStar
Examples:75%StarStarStarStar
Tests:-
Videos:-
Overall:67%StarStarStarStar
Rank:452