【问题标题】:Zend Framework escaping utf8 encoded charactersZend 框架转义 utf8 编码字符
【发布时间】:2010-12-23 17:33:32
【问题描述】:

我目前正在提取其他语言的提要数据。我执行以下操作并存储到 mysql 中。

$content = htmlentities($item->title, ENT_COMPAT, "UTF-8");

当我输出文本时,使用 $this->escape 它仍然会转义编码的实体。

所以我得到:á 而不是 á

有什么想法吗?

【问题讨论】:

  • 我不明白你的问题到底是什么?
  • 存储时不要编码数据,显示时编码。此外,Zend_View::escape() 在本机使用 htmlspecialcharsUTF-8 编码,除非被覆盖。

标签: php zend-framework


【解决方案1】:

不要做htmlentities,做htmlspecialcharshtmlentities编码了很多不需要甚至不应该编码的东西:

$content = htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8');

如果 feed 数据不是 utf-8 编码的,可能需要进行转换,之前htmlspecialchars:

$content = mb_convert_encoding($item->title, 'UTF-8', '<encoding of the other side>');

请注意,“另一方的编码”可能很重要。

顺便说一句,如果您打算将其输出为 HTML 而不进行任何过滤,请考虑将其存储为原生 HTML。

【讨论】:

  • 谢谢! htmlspecialchars 在不删除 $this->escape()! 的情况下解决了这个问题
猜你喜欢
  • 2013-02-07
  • 1970-01-01
  • 2015-03-07
  • 1970-01-01
  • 2014-03-05
  • 2013-04-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多