2010-12-23 127 views
0

我目前正在使用其他語言提供數據源數據。我做了以下並存儲到MySQL。Zend Framework轉義utf8編碼字符

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

當我輸出文本時,使用$ this-> escape它仍然會轉義編碼的實體。

所以我得到:á代替

任何想法?

+0

我不明白你的問題到底是什麼? – 2010-12-23 17:45:47

+0

不要在存儲數據時編碼數據,在顯示數據時對其進行編碼。另外,`Zend_View :: escape()`本身使用'htmlspecialchars`和`UTF-8`編碼,除非被覆蓋。 – Phil 2010-12-24 00:40:26

回答

1

不要做htmlentities,做htmlspecialcharshtmlentities編碼不需要甚至不應該被編碼的很多事情:

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

如果進數據UTF-8編碼不,你可能需要將其轉換,htmlspecialchars

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

注意,「對方的編碼」可能被證明非常重要的。順便說一句,如果你打算把它作爲HTML輸出而沒有任何過濾,可以考慮將它作爲原生HTML存儲起來。