json_encode与utf-8中的mysql内容和变音符号 [英] json_encode with mysql content and umlauts in utf-8

查看:108
本文介绍了json_encode与utf-8中的mysql内容和变音符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试找出问题所在时,我感到我的胡子越来越大.

i feel my beard growing while trying to find out the Problem here.

基本的问题是,Umlauts/特殊标志äöß...不起作用.我猜每个人都对这个问题感到厌倦,但是在网上找到的所有解决方案似乎都行不通.

Basic the Problem is, that Umlauts/Special Signs äöß ... don't work. I guess everyone is sick and tired of that questions but all the solutions found online don't seem to work.

我在utf-8 Mysql数据库中具有utf-8内容.我在数据库连接中的某个地方感觉到问题主义者,但我只是想不通.

Im having utf-8 content in a utf-8 Mysql Database. I feel the Problem ist somewhere in the Database connection but i just can't figure out.

character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem二进制文件
character_set_results utf8
character_set_server latin1
character_set_system utf8

character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem binary
character_set_results utf8
character_set_server latin1
character_set_system utf8

我不确定问题是否出在character_set_server的latin1上,因为我没有进入那个mysql东西.我也不知道该如何更改,因为我无法访问mysql服务器的配置文件.

Im not sure if the problem is the latin1 for character_set_server because im not into that mysql stuff. I also dont know how to change cause i can't access the mysql server's config files.

无论什么使我感到困惑,如果我从数据库中获取结果并回显它,则print_r会给出正确的结果.

Whatever is confusing me, that if i get my results from the Database and echo it, print_r gives the right result.

ini_set('default_charset','utf-8');
header('Content-Type: text/plain; > charset=utf-8');

Firefox说char编码是utf-8,但是如果我输出:

Firefox says char encode is utf-8 but if when i output:

print_r($listnew);
echo json_encode($listnew[5]);

print_r结果一切正确,但json_encode做错了.

print_r results everything right but json_encode does wrong.

print_r:

[5] => Array (
       [id] => 5
       [data] => U-Bahnhof Theresienstraße
       [size] => 17
)

json_encode:

json_encode:

{"id":5,数据":"U-Bahnhof Theresienstra \ u00dfe",大小":17}

{"id":5,"data":"U-Bahnhof Theresienstra\u00dfe","size":17}

我知道json_encode需要utf-8字符串才能在其中正常工作,我在这里遇到编码麻烦,但是我无法弄清它在哪里.

i know json_encode needs a utf-8 string to work properly there and i feel im having a encode trouble here but i just can't firgure out where it is.

任何帮助将不胜感激

提前谢谢.

i3

推荐答案

嗯...我认为这实际上是正确的方式. \u00dfß的正确unicode表示.当您将json_decode()放回原位时,它将再次变为ß.

Ummm... I think that is the correct way actually. \u00df is a correct unicode representation of ß. When you json_decode() it back, it will become ß again.

这会给您带来什么问题?接收端是否无法正确解码?如果您使用标准的json_*函数,则应该这样做.

Where is this making problems for you? Is the receiving end not decoding it properly? It should if you use standard json_* functions.

手册中的所有示例都显示相同的内容-超出ASCII范围的字符被转换为数字序列.

All the examples in the manual show the same thing - characters beyond the ASCII range are turned into numeric sequences.

这篇关于json_encode与utf-8中的mysql内容和变音符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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