提问人:Fifi 提问时间:1/6/2023 最后编辑:Fifi 更新时间:1/6/2023 访问量:159
PHP json 编码和 Node.js 解码utf8mb4_unicode_ci字符串
PHP json encode and Node.js decode utf8mb4_unicode_ci strings
问:
在我的服务器上,数据库是编码的,我正在编写一个 API 来提供 JSON 中的数据。
PHP 函数只接受 .utf8mb4_unicode_ci
json_encode
utf8
我无法构建完整的链:
strings encoded in utf8mb4_unicode_ci
=> utf8
=> json
=> API
=> JavaScript
=> strings encoded in utf8mb4_unicode_ci
例如$str = "Linéaire 😀"
;
从 到 我已经尝试了 PHP 函数,并分别返回:utf8mb4_unicode_ci
utf8
utf8_encode(str)
mb_convert_encoding($str, 'UTF-8', 'Windows-1252')
"Lin\u00c3\u00a9aire \u00f0\u009f\u0098\u0080"
"Lin\u00c3\u00a9aire \u00f0\u0178\u02dc\u20ac"
这两个函数不会返回相同的结果。我不知道该选择哪一个。 此外,我不知道如何在 JavaScript 中取消转义客户端的字符串。
答: 暂无答案
评论
utf8mb4_unicode_ci
SET NAMES 'utf8'
print json_encode($sth->fetchAll());
let data = JSON.parse(raw_json);
utf8
json_encode()
JSON_ERROR_UTF8
SET NAMES 'utf8'