Home > Backend Development > PHP Tutorial > fgetcsv读取不了中文解决办法

fgetcsv读取不了中文解决办法

WBOY
Release: 2016-06-13 10:21:26
Original
1091 people have browsed it

fgetcsv读取不了中文
已设置setlocale(LC_ALL, 'zh_CN'),但在读取csv文件的时候,有时不能读取里面的中文,这是为什么?跟系统系统好像有关系!

------解决方案--------------------
文档编码和系统编码相同吗,不相同的话iconv把文档编码转成系统编码。
------解决方案--------------------
fgetcsv有BUG。

用这个函数吧。


PHP code
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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template