我正在设置一个新服务器,并希望在我的Web应用程序中完全支持UTF-8.我过去曾在现有的服务器上尝试过此操作,但最终似乎不得不回归ISO-8859-1.
我在哪里需要设置编码/字符集?我知道我需要配置Apache,MySQL和PHP来执行此操作 - 是否有一些我可以遵循的标准清单,或者可能是在出现不匹配的地方进行故障排除?
这适用于运行MySQL 5,PHP,5和Apache 2的新Linux服务器.
我正在尝试这段代码
$json = file_get_contents("http://www.google.com/alerts/preview?q=test&t=7&f=1&l=0&e");
print_r(json_decode(utf8_encode($json), true));
//////////////
// Define the errors.
$constants = get_defined_constants(true);
$json_errors = array();
foreach ($constants["json"] as $name => $value) {
if (!strncmp($name, "JSON_ERROR_", 11)) {
$json_errors[$value] = $name;
}
}
// Show the errors for different depths.
foreach (range(4, 3, -1) as $depth) {
var_dump(json_decode($json, true, $depth));
echo 'Last error: ', $json_errors[json_last_error()], PHP_EOL, PHP_EOL;
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了很多函数,html_entities_decode,utf8_encode和解码,解码十六进制代码,但我总是得到错误"JSON_ERROR_UTF8".
我该怎么解决这个问题?