简体   繁体   English

将奇数字符编码转换回utf-8

[英]Converting odd character encoding back to utf-8

I have a database full of strings containing strange characters such as: 我有一个充满字符串的数据库,其中包含奇怪的字符,例如:

Design Tattoo Ãœbungshaut

Mehrflächiges Biozid Reinigungs- & Desinfektionsmittel

Where the Ãœ and ä should be, as I understand, an Ü and à when in proper UTF-8 . Üä应该是,按照我的理解,一个ÜÃ时在适当的UTF-8

Is there a standard function to revert these multiple characters back to there proper UTF-8 form? 是否有标准功能将这些多个字符还原为正确的UTF-8格式?

In PHP I have come across $url = iconv('utf-8', 'iso-8859-1', $url); PHP我遇到了$url = iconv('utf-8', 'iso-8859-1', $url); which seems to get close but falls short. 似乎接近但不足。 Perhaps I have the wrong parameters, but in any case was just wondering how well this issue is know and if there is an established fix? 也许我输入了错误的参数,但是无论如何,我只是想知道这个问题的认识程度,以及是否有已确定的解决方案?

The original data was taken from the eCommerce system CubeCart which seems to have no problem converting it back to normal text FYI. 原始数据来自电子商务系统CubeCart ,将其转换回普通文本FYI似乎没有问题。

The data shown as example is UTF-8 encoded data mistakenly interpreted as ISO-8859-1 (or windows-1252). 作为示例显示的数据是被UTF-8编码的数据错误地解释为ISO-8859-1(或Windows-1252)。 The problem combinations are in fact “Ü” and “ä” (“Ā” does not appear in German). 问题组合实际上是“Ü”和“ä”(德语中没有出现“Ā”)。 So apparently what you need to do is to read the data as UTF-8 and display it that way, instead of converting it. 因此,显然您需要做的是将数据读取为UTF-8并以这种方式显示,而不是对其进行转换。

If the database and output is utf-8 it could be because your not using utf-8 as the client character set. 如果数据库和输出是utf-8,则可能是因为您没有使用utf-8作为客户端字符集。

If your using mysqli you can use set_charset or run SET NAMES utf8 as a query before fetching data. 如果使用mysqli,则可以在获取数据之前使用set_charset或运行SET NAMES utf8作为查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM