当前位置:网站首页>乱码解决方案
乱码解决方案
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字符保持不变。
边栏推荐
- Cannot read properties of null (reading 'insertBefore')
- The cost of automated testing is high and the effect is poor, so what is the significance of automated testing?
- As soon as flink cdc is started, the CPU of the source Oracle server soars to more than 80%. What is the reason?
- canal实现mysql数据同步
- 7. Execution of special SQL
- 12、分页插件
- Unity DOTS学习教程汇总
- Dynamic programming of the division of numbers
- 【JS】js给对象动态添加、设置、删除属性名和属性值
- 8、自定义映射resultMap
猜你喜欢
随机推荐
MySQL数据库(基础)
4.3 基于注解的声明式事务和基于XML的声明式事务
warning C4251: “std::vector<_Ty>”需要有 dll 接口由 class“Test”的客户端使用错误
Interesting Kotlin 0x0E: DeepRecursiveFunction
Can‘t connect to MySQL server on ‘localhost3306‘ (10061) 简洁明了的解决方法
FPGA学习笔记——知识点总结
Summary of MySQL database interview questions (2022 latest version)
Write golang simple C2 remote control based on gRPC
TensorRT例程解读之语义分割demo
力扣:343. 整数拆分
Programming hodgepodge (4)
MySQL日期函数
Teenage Achievement Hackers Need These Skills
力扣:62.不同路径
[Evaluation model] Topsis method (pros and cons distance method)
Landing, the IFC, GFC, FFC concept, layout rules, forming method, use is analysed
心余力绌:企业面临的软件供应链安全困境
8. Custom mapping resultMap
程序员也应了解的Unity粒子系统
MySQL log articles, binlog log of MySQL log, detailed explanation of binlog log