PHP 该如何检测文件的编码呢
用户上传一个文件,页面上显示出内容,整个网站都是UTF-8,用户如果上传了GB的文件,就显示出乱码。
可以用mb_convert_encoding($text, "UTF-8 ", "GBK ");来转换,但如何确定用户上传的是GB编码的文件呢?
------解决方案--------------------
mb_check_encoding -- Check if the string is valid for the specified encoding
------解决方案--------------------
貌似楼上写错了
mb_detect_encoding( $string )
------解决方案--------------------
iconv也可以。。。。
------解决方案--------------------
$temstr=file_get_contents($path);
$encode = mb_detect_encoding($temstr, "ASCII,UTF-8,CP936,EUC-CN,BIG-5,EUC-TW ");
$temstr=mb_convert_encoding($temstr, "CP936 ", $encode);
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号