当前位置:网站首页>乱码解决方案
乱码解决方案
2022-08-04 05:25:00 【eleven_-11】
乱码解决办法
第一种 数据库中的数据乱码
问题重现
首先数据库连接工具使用的navicat
可以看到这里对数据库进行了utf8编码,即里面显示的数据编码是utf8

这里可以看到正常显示的文字编码格式就是utf8编码,乱码就不知道是什么最初未转码为utf8之前的编码格式了
测试乱码的编码格式
这里有一个测试乱码网站
http://www.mytju.com/classcode/tools/messyCodeRecover.asp
我们把乱码的字符串放上去检测
因为之前我们已经把所有的编码格式统一为utf8,所以现在测出来在windows-1252编码下是能够正常显示。
乱码处理
这里就采用哪个编码能够正常显示,就使用哪种编码格式
在查询数据库时候进行设置
mysql_query("SET NAMES 'UTF8'");
这样就固定了里面所有的字符编码为utf8,和navicat配置一致
public function codingConverter($sPendingCode)
{
$sOldStr = $sPendingCode;
$sNewStr = mb_convert_encoding($sPendingCode, 'WINDOWS-1252', 'utf8');
if (stripos($sNewStr, '?') === false) {
return $sNewStr;
} else {
return $sOldStr;
}
}
首先将所有的编码格式转化为windows-1252,如果之前的编码是utf8能够正常显示,那么转化为Windows1252则会损坏字符,变成????,这里就进行检测。
结论
针对于多个字符相互转换,且如果有的字符转换为utf8乱码,则采用把乱码的字符改为原有的编码格式,utf8字符保持不变。
边栏推荐
猜你喜欢

7.15 Day21---MySQL----Index

Web Basics and Exercises for C1 Certification - My Study Notes

Dynamic programming of the division of numbers

TSF微服务治理实战系列(一)——治理蓝图

Resolved error: npm WARN config global `--global`, `--local` are deprecated

企业需要知道的5个 IAM 最佳实践

4.3 Annotation-based declarative transactions and XML-based declarative transactions

idea设置识别.sql文件类型以及其他文件类型

代码重构:面向单元测试

The idea setting recognizes the .sql file type and other file types
随机推荐
8款最佳实践,保护你的 IaC 安全!
LCP 17. 速算机器人
符号表
Cannot read properties of null (reading ‘insertBefore‘)
Summary of MySQL database interview questions (2022 latest version)
string类简介
Performance testing with Loadrunner
渗透测试(PenTest)基础指南
Delphi-C端有趣的菜单操作界面设计
As soon as flink cdc is started, the CPU of the source Oracle server soars to more than 80%. What is the reason?
《看见新力量》第四期免费下载!走进十五位科技创业者的精彩故事
Sublime Text 3 2021.8.3 个人配置
The cost of automated testing is high and the effect is poor, so what is the significance of automated testing?
Do you think border-radius is just rounded corners?【Various angles】
TensorRTx-YOLOv5工程解读(一)
擎朗智能全国研发创新中心落地光谷:去年曾获2亿美元融资
Interesting Kotlin 0x0E: DeepRecursiveFunction
Dynamic programming of the division of numbers
部署LVS-DR群集【实验】
5个开源组件管理小技巧