未定义的变量:使用HTML净化器时,purify和方法名称必须是字符串

时间:2017-07-13 08:38:05

标签: php htmlpurifier

有错误的行:

$msg = $purifier->$purify($result['Message']);

错误:

Notice: Undefined variable: purify in /storage/ssd5/777/1537777/public_html/inc/ticketBody.php on line 41

Fatal error: Uncaught Error: Method name must be a string in /storage/ssd5/777/1537777/public_html/inc/ticketBody.php:41 Stack trace: #0 {main} thrown in /storage/ssd5/777/1537777/public_html/inc/ticketBody.php on line 41

配置:

require_once '../HTMLPurifier/library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.Allowed', 'div, *[style|class]');
$purifier = new HTMLPurifier($config);

我不明白这是什么问题......

1 个答案:

答案 0 :(得分:1)

应该是:

$purifier->purify($result['Message']);

docs中引用,而不是

$purifier->$purify($result['Message']);

您没有声明$purify变量,因此错误。

P.S:初始语法有效,因为您可能想要动态调用方法,请检查this