Skip to content
Derek Jones edited this page Jul 5, 2012 · 10 revisions

Download the distribution. Save in Application/helpers directory. Create file and name to htmlpurifier_helper.php

CREDITS:

[b]Author: Thorpe Obazee Updated for 2.0.x: Coccodrillo The original HTML Purifier package http://htmlpurifier.org/[/b]

htmlpurifier_helper.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

function purify($dirty_html)
{

     if (is_array($dirty_html))
    {
        foreach ($dirty_html as $key => $val)
        {
            $dirty_html[$key] = purify($val);
        }

        return $dirty_html;
    }

    if (trim($dirty_html) === '')
    {
        return $dirty_html;
    }

    require_once(APPPATH."helpers/library/htmlpurifier/HTMLPurifier.auto.php"); 
    require_once(APPPATH."helpers/library/htmlpurifier/HTMLPurifier.func.php");

    $config = HTMLPurifier_Config::createDefault();

    $config->set('HTML.Doctype', 'XHTML 1.0 Strict');

    return HTMLPurifier($dirty_html, $config);

}
?>

From the controller:

<?php
    public function cleanmyhtml()
    {
           $this->load->helper('htmlpurifier');
           $dirty_html = '<a >ds</a><p>test<br /><img src="noalt.jpg">';
           $clean_html = purify($dirty_html);
           echo $clean_html;
    }

?&gt;
Clone this wiki locally