user311509
user311509

Reputation: 2866

HTML Purifier Filter Elements

I would like to make sure my HTML Purifier removes all elements other than these:

br, a, img, div, embed, object, u, em, ul, ol, li, strong, span

these elements will have many attributes.

What can i do?

I thought to use strip_tags before going into purifier.

My code:

    $config = HTMLPurifier_Config::createDefault();
    $config->set('Attr.AllowedFrameTargets', array('_blank'));
    $config->set('HTML.SafeObject', true);
    $config->set('Output.FlashCompat', true);
    $config->set('HTML.SafeEmbed', true);

    $purifier = new HTMLPurifier($config);

Upvotes: 1

Views: 650

Answers (1)

Aurelio De Rosa
Aurelio De Rosa

Reputation: 22152

You can do this:

$ValidTags = '*[id|class|name],br,a[href|title|rel|target],' .
'img[src|alt|height|width],div,embed,' .
'object,u,em,ul,ol,li,strong,span';
$config->set('HTML.Allowed', $ValidTags);

Note: *[id|class|name] means that you allow for all the accepted tags the attributes id, class and name (which are usually usefull).

Upvotes: 2

Related Questions