PHP Classes

File: example/example.php

Recommend this page to a friend!
  Classes of Simon Emery   allowHTML   example/example.php   Download  
File: example/example.php
Role: Example script
Content type: text/plain
Description: Example of class usage
Class: allowHTML
Filter insecure HTML following OWASP AntiSamy
Author: By
Last change:
Date: 13 years ago
Size: 846 bytes


Class file image Download

Further examples available at the link below:

//load allowhtml

//raw html
$raw_html = '<p align="left" style="background:#000; border:1px solid #EEE;">Hello world!</p><script>alert(\'danger!\');</script>';

//set options
$options = array(
'allowed_tags' => array( "p", "br", "a" ), //allowing <p><br /><a> html tags only
'allowed_attr'=> array( "align", "style" ), //allowing 'align' and 'style' html arrtibutes only
'allowed_css' => array( "background" ), //allowing 'background' css property only

//set method
$method = "sanitize"; //choose between 'sanitize' and 'validate'

//use class wrapper function
$safe_html = allowHTML($raw_html, $options, $method);

//view source
echo htmlentities($safe_html, ENT_QUOTES, "UTF-8");