2017 © Pedro Peláez
 

library yodo

Simple, fast and customizable HTML sanitizer

image

funddy/yodo

Simple, fast and customizable HTML sanitizer

  • Monday, May 20, 2013
  • by funddy
  • Repository
  • 2 Watchers
  • 9 Stars
  • 63 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Yodo

Build Status, (*1)

Simple, fast and customizable HTML sanitizer., (*2)

Setup and Configuration

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

Usage

<?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)

The Versions

20/05 2013

dev-master

9999999-dev https://github.com/funddy/yodo

Simple, fast and customizable HTML sanitizer

  Sources   Download

MIT

The Requires

  • php >=5.3.6

 

The Development Requires

html sanitizer