Analysis of PHP plugin htmlpurifier HTML Parser _php Tutorial

Source: Internet
Author: User
Tags autoload
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.