Skip to content
captainkuro edited this page Jan 10, 2013 · 11 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;
    }

?>
Clone this wiki locally