无法解码我的 HTML 个实体

Can't decode my HTML entities

我正在像这样存储我的原始 html...

nl2br(htmlentities($this->input->post('raw_html')))

在我的数据库中,数据如下所示...

<ul>                                 <li>Improve our understanding of this issue</li>                                 <li>Strengthen your listening and writing skills</li>                             </ul>

当我尝试显示我的数据库中的标记时,我使用了这个:

echo html_entity_decode($html_from_db, ENT_COMPAT, 'UTF-8');

但是我在浏览器中显示了这个输出:

<ul> <li>Improve our understanding of this issue</li> <li>Strengthen your listening and writing skills</li> </ul>
Lesson name

并且 html 个实体显示在我的源代码中...因此没有实体被解码。

为什么这不起作用?

可能当您使用 htmlentities 进行编码时,您编码了两次。请参阅函数参数:

function htmlentities ($string, $quote_style = null, $charset = null, $double_encode = true) {}

所以你可以试试这个:

nl2br(htmlentities($this->input->post('raw_html'), ENT_QUOTES, 'UTF-8', false))