gpt4 book ai didi

php - UTF-8 和 ISO-8859-1 : Why does it work for the most of the time and why sometimes not?

转载 作者:行者123 更新时间:2023-11-29 02:33:55 26 4
gpt4 key购买 nike

我有一个 osCommerce 2.2 MST,其中有一些自定义添加项。 osCommerce 本身属于 ISO-8859-1。添加在 MySQL 数据库中有一个表,现在在 utf8_general_ci 中(其他都在 latin1_swedish_ci 中)。我正在调用输出的 php 文件

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

正如我之前提到的,数据库中的数据是 UTF-8 格式的。但是像 ö,ä,ü 这样的字母是正确显示的。怎么会这样?应该没有 utf8_decode。但是字母 č 显示为 ?。我直接将其作为结果数组获取。如果我使用 phpmyadmin 进行查询,它会正确显示。

我设法让所有字母正确显示(仅在脚本的一个部分)。这是我做的

mysql_query("SET NAMES 'utf8'"); 

在我添加的 php-script 中

header('content-type: text/html; charset=utf-8');
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">

但随后又出现了其他问题。

我想知道为什么 UTF-8 格式的数据在不应该显示的时候却“正确”显示。以及如何正确显示字母 č?

我觉得这个系统相当复杂。我在哪里以及如何查看这里出了什么问题?

最佳答案

我不知道您的数据经过的编码/解码顺序,但 ö、ä 和 ü 等字母正确而 č 不正确的原因是 ö、ä 和 ü 可以以 ISO-8859-1 编码,但 č 不能。您需要在 HTML 中使用 UTF-8 而不是 ISO-8859-1 才能显示 č。

关于php - UTF-8 和 ISO-8859-1 : Why does it work for the most of the time and why sometimes not?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8247180/

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