fgetcsv读取不了中文
已设置setlocale(LC_ALL, 'zh_CN'),但在读取csv文件的时候,有时不能读取里面的中文,这是为什么?跟系统系统好像有关系!
------解决方案--------------------
文档编码和系统编码相同吗,不相同的话iconv把文档编码转成系统编码。
------解决方案--------------------
fgetcsv有BUG。
用这个函数吧。
function _fgetcsv(& $handle, $length = null, $d = ',', $e = '"') {
$d = preg_quote($d);
$e = preg_quote($e);
$_line = "";
$eof=false;
while ($eof != true) {
$_line .= (empty ($length) ? fgets($handle) : fgets($handle, $length));
$itemcnt = preg_match_all('/' . $e . '/', $_line, $dummy);
if ($itemcnt % 2 == 0)
$eof = true;
}
$_csv_line = preg_replace('/(?: |[ ])?$/', $d, trim($_line));
$_csv_pattern = '/(' . $e . '[^' . $e . ']*(?:' . $e . $e . '[^' . $e . ']*)*' . $e . '|[^' . $d . ']*)' . $d . '/';
preg_match_all($_csv_pattern, $_csv_line, $_csv_matches);
$_csv_data = $_csv_matches[1];
for ($_csv_i = 0; $_csv_i <font color="#e78608">------解决方案--------------------</font><br>fgetcsv的bug就是读取不了中文。。。
<br><font color="#e78608">------解决方案--------------------</font><br>确实,感觉即使5.3了,对多字节的支持还是不是很好
<br><font color="#e78608">------解决方案--------------------</font><br>其实是 php5.3 出问题了<br><div class="clear"></div>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号