修复损坏的 UTF

编程入门 行业动态 更新时间:2024-10-27 12:37:37
本文介绍了修复损坏的 UTF-8 编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在修复一些错误的 UTF-8 编码.我目前正在使用 PHP 5 和 MySQL.

I am in the process of fixing some bad UTF-8 encoding. I am currently using PHP 5 and MySQL.

在我的数据库中,我有一些错误编码的实例,它们打印如下:î

In my database I have a few instances of bad encodings that print like: î

数据库排序规则为 utf8_general_ciPHP 正在使用正确的 UTF-8 标头Notepad++ 设置为使用无 BOM 的 UTF-8数据库管理在 phpMyAdmin 中处理并非所有重音字符的情况都被破坏

我需要某种函数来帮助我将 î、ÃÂ、ü 和其他类似的实例映射到它们正确的带重音的 UTF-8 字符.

I need some sort of function that will help me map the instances of î, í, ü and others like it to their proper accented UTF-8 characters.

推荐答案

过去我不得不尝试修复"一些 UTF8 损坏的情况,不幸的是,这绝非易事,而且通常是不可能的.

I've had to try to 'fix' a number of UTF8 broken situations in the past, and unfortunately it's never easy, and often rather impossible.

>

除非你能确切地确定它是如何被破坏的,而且它总是以完全相同的方式被破坏,否则很难消除"损害.

Unless you can determine exactly how it was broken, and it was always broken in that exact same way, then it's going to be hard to 'undo' the damage.

如果您想尝试消除损坏,最好的办法是开始编写一些示例代码,在其中尝试对 mb_convert_encoding() 的调用进行多种变体,以查看是否可以找到'from' 和 'to' 的组合可以修复您的数据.最后,通常最好不要因为所涉及的痛苦程度而担心修复旧数据,而只是修复未来的事情.

If you want to try to undo the damage, your best bet would be to start writing some sample code, where you attempt numerous variations on calls to mb_convert_encoding() to see if you can find a combination of 'from' and 'to' that fixes your data. In the end, it's often best to not even bother worrying about fixing the old data because of the pain levels involved, but instead to just fix things going forward.

但是,在执行此操作之前,您需要确保首先修复导致此问题的所有内容.您已经提到您的数据库表整理和编辑器设置正确.但是还有更多地方需要检查以确保一切都正确地使用 UTF-8:

However, before doing this, you need to make sure that you fix everything that is causing this issue in the first place. You've already mentioned that your DB table collation and editors are set properly. But there are more places where you need to check to make sure that everything is properly UTF-8:

确保您以 UTF-8 格式提供 HTML:header("Content-Type: text/html; charset=utf-8"); ini_set("default_charset", 'utf-8'); 字符集 utf8 AddDefaultCharset UTF-8

如果您在整个过程中遗漏了任何一步,编码可能会被破坏并出现问题.但是,一旦你进入了 utf-8 的凹槽",这一切就变成了第二天性.当然,PHP6 应该是来自 getgo 的完全 unicode 投诉,这将使很多事情变得更容易(希望如此)

If you miss up on any one step through your whole process, the encoding can be mangled and problems arise. Once you get in the 'groove' of doing utf-8 though, this all becomes second nature. And of course, PHP6 is supposed to be fully unicode complaint from the getgo, which will make lots of this easier (hopefully)

这篇关于修复损坏的 UTF-8 编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-15 13:04:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/865684.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:UTF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!