Htmlpurifier plug-in usage
Download Htmlpurifier Plugin
The useful part of the Htmlpurifier plugin is the library
using Htmlpurifier Library class libraries
The first way
Copy CodeThe code is as follows:
Require_once ' HTMLPurifier.auto.php ';
$config = Htmlpurifier_config::createdefault ();
?>
or
Copy CodeThe code is as follows:
Require_once ' HTMLPurifier.includes.php ';
Require_once ' HTMLPurifier.autoload.php ';
$config = Htmlpurifier_config::createdefault ();
?>
The example given by the official website is
Copy CodeThe code is as follows:
Require_once ' HTMLPurifier.auto.php ';
what my colleague used to do
Copy CodeThe code is as follows:
Require_once ' HTMLPurifier.includes.php ';
Require_once ' HTMLPurifier.autoload.php ';
set $config
Configdoc
Http://htmlpurifier.org/live/configdoc/plain.html
Example
Copy CodeThe code is as follows:
$config->set (' HTML. Allowedelements ', Array (' div ' =>true, ' table ' =>true, ' tr ' =>true, ' TD ' =>true, ' BR ' =>true));
$config->set (' HTML. Doctype ', ' XHTML 1.0 Transitional ')//html document type (permanent)
$config->set (' core.encoding ', ' UTF-8 ')//character encoding (permanent)
HTML-allowed elements
div element, table element, TR element, TD element, BR element
New Htmlpurifier Object
Copy CodeThe code is as follows:
$purifier = new Htmlpurifier ($config);
Call the Purify method of the Htmlpurifier object
Copy CodeThe code is as follows:
$puri _html = $purifier->purify ($html);
The second way
Customizing a class htmlpurifier.php
Copy CodeThe code is as follows:
Require_once ' HTMLPurifier.includes.php ';
Require_once ' HTMLPurifier.autoload.php ';
Class Resume_htmlpurifier implements zend_filter_interface{
protected $_htmlpurifier = null;
Public function __construct ($options = null)
{
$config = Htmlpurifier_config::createdefault ();
$config->set (' code.encoding ', ' UTF-8 ');
$config->set (' HTML. Doctype ', ' XHTML 1.0 Transitional ')
if (!is_null ($options)) {
foreach ($options as $option) {
$config->set ($option [0], $option [1], $option [2]);
}
}
$this->_htmlpurifier = new Htmlpurifier ($config);
}
Public Function filter ($value)
{
return $this->_htmlpurifier->purify ($value);
}
}
?>
setting config information
For example:
Copy CodeThe code is as follows:
$conf = Array (
Array (' HTML. Allowedelements ',
Array
' div ' = true,
' Table ' = True,
' TR ' = True,
' TD ' = True,
' BR ' = True,
),
FALSE),//Allow attribute div table tr td BR Element
Array (' HTML. Allowedattributes ', Array (' class ' = TRUE), false),//Allow attribute class
Array (' attr.forbiddenclasses ', Array (' resume_p ' = ' = TRUE '), false),//Prohibit classes as
Array (' Autoformat.removeempty ', true, false),//Go to space
Array (' AutoFormat.RemoveEmpty.RemoveNbsp ', true, false),//Go to nbsp
Array (' URI '. Disable ', True, false),
);
called
Copy CodeThe code is as follows:
$p = new Resume_htmlpurifier ($conf);
$puri _html = $p->filter ($html);
http://www.bkjia.com/PHPjc/327964.html www.bkjia.com true http://www.bkjia.com/PHPjc/327964.html techarticle Htmlpurifier plug-in use download Htmlpurifier plug-in Htmlpurifier plugin useful part is the library using the Htmlpurifier Library class library The first way to copy code is as follows:? PHP re ...