dev-master
9999999-dev https://github.com/funddy/yodoSimple, fast and customizable HTML sanitizer
MIT
The Requires
- php >=5.3.6
The Development Requires
html sanitizer
Wallogit.com
2017 © Pedro Peláez
Simple, fast and customizable HTML sanitizer
Simple, fast and customizable HTML sanitizer., (*2)
Add the following to your composer.json file:, (*3)
{
"require": {
"funddy/yodo": "1.0.*"
}
}
Update the vendor libraries:, (*4)
curl -s http://getcomposer.org/installer | php php composer.phar install
<?php
require 'vendor/autoload.php';
use Funddy\Yodo\MarkupFixer\TidyMarkupFixer;
use Funddy\Yodo\Rule\RuleSet;
use Funddy\Yodo\Sanitizer\HtmlSanitizer;
$rules = new RuleSet();
$rules
->rule('p')
->attribute('class')
->in(array('class1', 'class2'))
->optional()
->trim()
->end()
->allowedChildren(array('a'))
->end()
->rule('br')
->toBeEmpty()
->end()
->rule('a')
->attribute('href')->like('/^http:\/\/.*?$/')->end()
->attribute('rel')->equals('nofollow')->optional()->end()
->end();
$sanitizer = new HtmlSanitizer($rules, new TidyMarkupFixer());
$html = <<<HTML
<p>This is an awesome paragraph!<a href="javascript:alert('oh')">with evil links inside!</a></p>
This tag is not allowed!
<br/>
<a href="http://example.com/">Valid link</a>
Paragraph with valid link, (*5)
Awesome!
HTML;
echo $sanitizer->sanitize($html);
The output will be, (*6)
This is an awesome paragraph!, (*7)
<br><a href="http://example.com/">Valid link</a>Paragraph with valid link, (*8)
Simple, fast and customizable HTML sanitizer
MIT
html sanitizer