gpt4 book ai didi

php - json_encode 运行时警告 "Invalid UTF-8 sequence"

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:01:17 24 4
gpt4 key购买 nike

我从数据库中检索一个 mysqli-resultset,它来自一个 utf-8 编码的表,然后被插入到一个数组中:

$json = array();

$query = "select artikel_titel from tblArtikel";
if($result = mysqli_query($link, $query))
{
while($line = mysqli_fetch_array($result, MYSQLI_NUM)) {
array_push($json, $line);
}
echo json_encode($json);

数组已正确构建,you can see it here在页面底部,您可以看到由 json_encode 创建的错误。我该如何解决这个问题?

Warning: json_encode(): Invalid UTF-8 sequence in argument in /customers/6/0/6/onezeromany.com/httpd.www/php/getArticles.php on line 13 Warning: json_encode(): Invalid UTF-8 sequence in argument in /customers/6/0/6/onezeromany.com/httpd.www/php/getArticles.php on line 13 Warning: json_encode(): Invalid UTF-8 sequence in argument in /customers/6/0/6/onezeromany.com/httpd.www/php/getArticles.php on line 13

最佳答案

确实在您的数据中有一个无效的 UTF-8 序列;显然你的数据库结果是 ISO-8859-1。根据 the docsjson_encode 适用于 UTF-8 数据.您必须确保您的数据是 UTF-8 格式,并且您的数据库连接也使用 UTF-8;或者,您可以使用 iconv()在将结果提供给 json_encode 之前将结果转换为 UTF-8。

关于php - json_encode 运行时警告 "Invalid UTF-8 sequence",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11413116/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com