明明txt展示的内容是832219957288977295565,导入到数据库成�8�3�2�2�1�9�9�5�7�2�8�8�9�7�7�2�9�5�5�6�5�,调试打印数字之间有空格
以为通过 $result1 = iconv("gbk", "utf-8//IGNORE",$result[1]);函数就可以解决,经过多次验证终于找到了解决方法
UTF16-LE编码的问题,具体实现代码参考如下
<?php
$filepath='E:\360Downloads\123.txt';
//必须安装fileinfo组件
$finfo = new finfo(FILEINFO_MIME_ENCODING);$encoding = $finfo->file($filepath);
echo "文件编码: " . $encoding;
$handle = fopen($filepath, "r");
if($encoding=="utf-16le"){
stream_filter_append($handle, "convert.iconv.UTF-16LE/UTF-8", STREAM_FILTER_READ);
}
while (($row = fgetcsv($handle)) !== false) {
echo $row[0] . " " . $row[1] . " " . $row[2] . " " . $row[3] . " " . $row[4];
}
相关文章