php将其他编码转成utf8的方法:1、创建一个PHP示例文件;2、找出字符串本身的编码;3、通过mb_convert_encoding转换为utf-8编码即可。

本文操作环境:Windows7系统,PHP7.4版,Dell G3电脑。
php将任意编码的内容转换成utf-8
思路
立即学习“PHP免费学习笔记(深入)”;
先找出字符串本身的编码,再转换为utf-8编码。
方法
function str_to_utf8 ($str = '') {
$current_encode = mb_detect_encoding($str, array("ASCII","GB2312","GBK",'BIG5','UTF-8'));
$encoded_str = mb_convert_encoding($str, 'UTF-8', $current_encode);
return $encoded_str;
}
推荐学习:《PHP视频教程》
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号