문제

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