当前位置:网站首页>乱码解决方案
乱码解决方案
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字符保持不变。
边栏推荐
- 擎朗智能全国研发创新中心落地光谷:去年曾获2亿美元融资
- 力扣:63. 不同路径 II
- Delphi-C端有趣的菜单操作界面设计
- day13--postman interface test
- 代码重构:面向单元测试
- [Cloud Native--Kubernetes] Pod Resource Management and Probe Detection
- C Expert Programming Chapter 5 Thinking about Linking 5.2 Advantages of Dynamic Linking
- Gartner 权威预测未来4年网络安全的8大发展趋势
- npm报错Beginning October 4, 2021, all connections to the npm registry - including for package installa
- JS basics - forced type conversion (error-prone, self-use)
猜你喜欢

8. Custom mapping resultMap

利用Jenkins实现Unity自动化构建

Web Basics and Exercises for C1 Certification - My Study Notes

Can‘t connect to MySQL server on ‘localhost3306‘ (10061) 简洁明了的解决方法

FPGA学习笔记——知识点总结

idea设置识别.sql文件类型以及其他文件类型
![[Evaluation model] Topsis method (pros and cons distance method)](/img/e7/c24241faced567f3e93f6ff3f20074.png)
[Evaluation model] Topsis method (pros and cons distance method)

入坑软件测试的经验与建议

Summary of MySQL database interview questions (2022 latest version)

7.15 Day21---MySQL----索引
随机推荐
7.16 Day22---MYSQL(Dao模式封装JDBC)
嵌入式系统驱动初级【4】——字符设备驱动基础下_并发控制
Wwise入门和实战
Can 't connect to MySQL server on' localhost3306 '(10061) simple solutions
Several ways to heavy
7.15 Day21---MySQL----索引
Get the selected content of the radio box
[Cloud Native--Kubernetes] Pod Resource Management and Probe Detection
Canal mysql data synchronization
处理List<Map<String, String>>类型
The cost of automated testing is high and the effect is poor, so what is the significance of automated testing?
TensorRT例程解读之语义分割demo
Programming hodgepodge (4)
Grain Mall - Basics (Project Introduction & Project Construction)
力扣:343. 整数拆分
The string class introduction
7、特殊SQL的执行
OpenCV获取和设置图像的平均亮度
如何低成本修bug?测试左移给你答案
7.13 Day20----MYSQL