Вопрос

I am using HTMLPurifier with an input textarea where users are allowed to put their HTML tag. Config is default:

        $config = HTMLPurifier_Config::createDefault();
        $purifier = new HTMLPurifier($config);
        $_POST['txt'] = $purifier->purify($_POST['txt']);

The problem I am getting is when the users put some > in the text, for example:

<p>Some text > other text </p>

This gets converted to:

<p>Some text &gt; other text </p>

Is there any way to stop that conversion? Without doing the oblivious:

$_POST['txt'] = str_replace('&gt;','>',$_POST['txt']);
Это было полезно?

Решение

If this conversion doesn't happen, the HTML will be invalid. If that's what you want, there may be a config option for that.

Другие советы

as you probably know &gt; html special character for >. Browser will render everything properly.

You can try using htmlspecialchars_decode to decode all special chars to original values.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top