PHP字符编码问题 [英] PHP character encoding problems
问题描述
我需要帮助一个字符编码问题,我想一劳永逸。这里是一个例子,我从一个XML feed,插入我的数据库,然后拉出一些内容。
正如你看不到的,很多特殊的html字符被破坏/破坏。
我如何一劳永逸?我如何支持所有类型的字符等。
我已经尝试过每一个编码我可以找到,它有时纠正它,但大多数,但仍然
$ header('Content-type:text / html; charset = UTF-8');
/ **
*为UTF-8安全地编码HTML。使用而不是htmlentities。
*
* @param string $ var
* @return string
* /
function html_encode($ var)
{
return htmlentities ($ var,ENT_QUOTES,'UTF-8');
}
这两个人救了我,我想现在工作。如果我继续遇到问题,我会回来。我应该把它存储在DB中,例如作为&或作为&?
I need help with a character encoding problem that I want to sort once and for all. Here is an example of some content which I pull from a XML feed, insert into my database and then pull out.
As you can not see, a lot of special html characters get corrupted/broken.
How can I once and for all stop this? How am I able to support all types of characters, etc.?
I've tried literally every piece of coding I can find, it sometimes corrects it for most but still others are corrupted.
header('Content-type: text/html; charset=UTF-8') ;
/**
* Encodes HTML safely for UTF-8. Use instead of htmlentities.
*
* @param string $var
* @return string
*/
function html_encode($var)
{
return htmlentities($var, ENT_QUOTES, 'UTF-8');
}
Those two rescued me and I think it is now working. I'll come back if I continue to encounter problems. Should I store it in the DB, eg as "&" or as "&"?
这篇关于PHP字符编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!