utf8_encode不会产生正确的结果 [英] utf8_encode does not produce right result

查看:359
本文介绍了utf8_encode不会产生正确的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是以下:

我存储一个数组,其中有e,f等键。获取键的值。这工作得很好。但如果我想存储í,é等作为键,它不会产生正确的结果(结果在 )。我的页面必须是UTF-8。查找问题,我发现utf8_encode应该帮助我的问题。它没有:虽然它产生一个更易读的字符,它仍然完全不同于我想要的。如果重要,phpinfo给出:

I store an array, which has keys like "e", "f", etc. At some point, I have to get the value of the key. This works well. But if I want to store "í", "é", etc. as the keys, it won't produce the right result (results in �). My page has to be in UTF-8. Looking up the problem, I found out that utf8_encode should help my problem. It didn't: although it produced a more-readable character, it still totally differed from what I want. If important, phpinfo gives:

Directive   Local Value Master Value
iconv.input_encoding    ISO-8859-1  ISO-8859-1
iconv.internal_encoding ISO-8859-1  ISO-8859-1
iconv.output_encoding   ISO-8859-1  ISO-8859-1

有什么可以帮助问题?

编辑:我认为数组键使一些数据丢失。是真的吗?如果是,如何防止?

Edit: I think that array keys make some data loss. Is it true? If yes, how to prevent?

Edit2:我试过的解决方案:使用相同的键,但值为utf-8个字符的数组:失败; utf8_encode failed; [试过两个] iconv_set_encoding:失败; ini_set失败; mb_internal_encoding失败。

Solutions I've tried so far: get the array key value - failed; make an array with same keys but a values of utf-8 characters: failed; utf8_encode failed; [tried with both] iconv_set_encoding: failed; ini_set failed; mb_internal_encoding failed. All returned with either à or �.

推荐答案

我已经整理了一些解决方案,最后它的工作原理。

I've put together some solutions and finally it works.

我所做的是以下操作:
首先,我已经把所有的解决方案放在一起添加了这一行:

What I've done is the following: First, I've put together all solutions with adding this line:

ini_set('default_charset', 'UTF-8');
iconv_set_encoding("input_encoding", "UTF-8");
iconv_set_encoding("internal_encoding", "UTF-8");
iconv_set_encoding("output_encoding", "UTF-8");
mb_internal_encoding("UTF-8");

这不起作用。

看了所有的链接,utf8_encode - utf8_decode方法没有工作。然后我看看函数,我发现mbstring,所以我用它的 mbstring 等同。

I looked at all the links, the utf8_encode - utf8_decode method didn't work. Then I took a look at the functions, I found the mbstring, so I replaced every string function with its mbstring equivalent.

这很好。然后,我想出, mb_internal_encoding(UTF-8); 就够了。所以现在它的工作。感谢所有的建议!

This worked fine. Then, I figured out that mb_internal_encoding("UTF-8"); is enough. So now it works. Thanks for all the suggestions!

这篇关于utf8_encode不会产生正确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆