Generated: Fri Feb 13 22:26:25 UTC 2015
HTMLFilter
==========
[](https://travis-ci.org/attilammagyar/html-filter) [Latest build report][latestbuild]
[latestbuild]: http://attilammagyar.github.io/html-filter/
Remove tags or attributes based on a whitelist from a snippet of somewhat
well-formatted HTML text using PHP's DOM library.
Example:
```php
<?php
$config = new AthosHun\HTMLFilter\Configuration();
$config->allowTag("p")
->allowAttribute("a", "title")
->allowAttribute("a", "href", "|^https?://.*\$|");
$filter = new AthosHun\HTMLFilter\HTMLFilter();
$html = <<<HTML
Lorem ipsum <em>dolor</em> sit amet
<p>
Consectetur <a href="http://example.com" title="hey!">adipisicing</a>
<a href="javascript:alert(42)" onclick="alert(42)">elit</a>.
</p>
HTML;
print $filter->filter($config, $html);
```
Output:
```html
Lorem ipsum dolor sit amet
<p>
Consectetur <a href="http://example.com" title="hey!">adipisicing</a>
<a>elit</a>.
</p>
```
Installation
------------
Installation is possible via [Composer][composer]. Create a file named
`composer.json` in your project directory with the following contents:
[composer]: http://getcomposer.org/
{
"require": {
"athoshun/html-filter": "2.0.*"
}
}
Then as a normal user, issue the following commands:
$ curl http://getcomposer.org/installer | php
$ php composer.phar install
PHPUnit 3.7.38 by Sebastian Bergmann. Configuration read from /home/travis/build/attilammagyar/html-filter/phpunit.xml .................. Time: 166 ms, Memory: 4.50Mb OK (18 tests, 30 assertions) Generating code coverage report in Clover XML format ... done Generating code coverage report in HTML format ... done Code Coverage Report 2015-02-13 22:26:23 Summary: Classes: 75.00% (3/4) Methods: 97.96% (48/49) Lines: 99.19% (245/247)