Welcome Guest, Not a member yet? Register   Sign In
HTMLPurify in Codeigniter 4
#1

(This post was last modified: 01-01-2021, 07:20 PM by php_rocs.)

Hello all

I'm trying to use HTMLPurify from this : htmlpurifier.org but it keeps getting error :

Here when I useit  in my traits:


PHP Code:
use ThirdParty\Purifier\Purifier;
trait 
ValidationMaster{

public function 
omit_script($val){
 
$htmlpf = new Purifier($val);
 
$k $htmlpf->purify($val);
 return 
$k
 
}



Here is my Purify.php located in App\ThirdParty\HTMLPurifier
PHP Code:
<?php

namespace ThirdParty\Purifier;

class 
Purifier{
        public $dirty_html;

    public function 
__construct($dt){
                $this->dirty_html $dt;
        require_once 
'htmlpurifier-4.13.0/library/HTMLPurifier.auto.php';

        
$config HTMLPurifier_Config::createDefault();
        
$purifier = new HTMLPurifier($config);
        
$clean_html $purifier->purify($this->dirty_html);

        echo 
$clean_html;        
    }


The error :

Quote:
Quote:Class 'ThirdParty\Purifier\HTMLPurifier_Config' not found
APPPATH\ThirdParty\HtmlPurifier\Purifier.php at line 11

It seems like the Purifier.php does not load HTMLPurifier.auto.php.

How can I use this library in Codeigniter 4 ?

Thanks in advance and Happy New Year
Reply
#2

When you call the class "$config = HTMLPurifier_Config::createDefault();" it is called in the "namespace ThirdParty\Purifier;"

HTML Purifier library classes do not have "ThirdParty\Purifier" namespace.

Add a backslash before the class name. This will take the class out of the current namespace into the global namespace.
$config = \HTMLPurifier_Config::createDefault();
Reply
#3

Thanks for the answer. I will try it this night.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB