json_encode和波斯语? [英] json_encode and persian words?

查看:233
本文介绍了json_encode和波斯语?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 json_encode 插入一个值数组(如:< input name =ok []> ... 在数据库中,不知道为什么它插入波斯语作为 [\\\س\\\ی\\\د \\\ی \\\د \\ \\ u062f\\\ا\\\د\\\ا\\\ش\\\ز\\\ا\\\د\\\ه] 它之前插入为:سییدداداشزاده

I am using json_encode for inserting a value array (like: <input name="ok[]">... in the database, don't know why it inserted Persian words as ["\u0633\u06cc\u062f \u0633\u0639\u06cc\u062f \u062f\u0627\u062f\u0627\u0634\u0632\u0627\u062f\u0647"] it was earlier inserted as: سید سعید داداشزاده.

输出数据库( select * from tabla ... )by json_encode [\\\\\س\\\\ی\\\\د \\\\س\\ u0639\\\\ی\\\\د \\\\د\\\\د\\\\د\\\\ا\\\\ش\\\\ز\\\\ا\\ u062f \\\\ه\]

Output of database (select * from tabla ...) by json_encode is as:[\"\\u0633\\u06cc\\u062f \\u0633\\u0639\\u06cc\\u062f \\u062f\\u0627\\u062f\\u0627\\u0634\\u0632\\u0627\\u062f\\u0647\"]"

在数据库的my表中,此行的排序规则为 utf8_general_ci

In the my table (of database), Collation of this row is utf8_general_ci?

我可以为 print(output of database)波斯语为سیدسعیدداداشزاده

推荐答案

json_encode 将所有非ASCII字符与 \uXXXX 符号。这不是问题,因为任何json解码器和javascript,识别这个符号:

json_encode encodes all non-ascii characters with the \uXXXX notation. This is not a problem, because any json decoder, and javascript, recognize this notation:

json_decode('["\u0633\u06cc\u062f \u0633\u0639\u06cc\u062f \u062f\u0627\u062f\u0627\u0634\u0632\u0627\u062f\u0647"]');
// array('سید سعید داداشزاده')

你从数据库中获取的数据被转义。它在插入数据库之前已经被双重转义,或者启用了magic_quotes_runtime。在使用 stripslashes =http://php.net/json_decode =nofollow> json_decode ,以解除转义:

However, it seems that the string that you get from the database is escaped. Either it has been double-escaped before inserting in the database, or you have magic_quotes_runtime enabled. Use stripslashes on the json string, before using json_decode, to un-escape it:

json_decode(stripslashes('[\"\\u0633\\u06cc\\u062f \\u0633\\u0639\\u06cc\\u062f \\u062f\\u0627\\u062f\\u0627\\u0634\\u0632\\u0627\\u062f\\u0647\"]'));

这篇关于json_encode和波斯语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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