Home >Backend Development >PHP Tutorial >fgetcsv读取不已中文

fgetcsv读取不已中文

WBOY
WBOYOriginal
2016-06-13 12:03:39983browse

fgetcsv读取不了中文
已设置setlocale(LC_ALL, 'zh_CN'),但在读取csv文件的时候,有时不能读取里面的中文,这是为什么?跟系统系统好像有关系!
------解决方案--------------------
文档编码和系统编码相同吗,不相同的话iconv把文档编码转成系统编码。
------解决方案--------------------
fgetcsv有BUG。

用这个函数吧。


<br />function _fgetcsv(& $handle, $length = null, $d = ',', $e = '"') {<br />     $d = preg_quote($d);<br />     $e = preg_quote($e);<br />     $_line = "";<br />     $eof=false;<br />     while ($eof != true) {<br />         $_line .= (empty ($length) ? fgets($handle) : fgets($handle, $length));<br />         $itemcnt = preg_match_all('/' . $e . '/', $_line, $dummy);<br />         if ($itemcnt % 2 == 0)<br />             $eof = true;<br />     }<br />     $_csv_line = preg_replace('/(?: <br><font color='#FF8000'>------解决方案--------------------</font><br>[ ])?$/', $d, trim($_line));<br />     $_csv_pattern = '/(' . $e . '[^' . $e . ']*(?:' . $e . $e . '[^' . $e . ']*)*' . $e . '<br><font color='#FF8000'>------解决方案--------------------</font><br>[^' . $d . ']*)' . $d . '/';<br />     preg_match_all($_csv_pattern, $_csv_line, $_csv_matches);<br />     $_csv_data = $_csv_matches[1];<br />     for ($_csv_i = 0; $_csv_i < count($_csv_data); $_csv_i++) {<br />         $_csv_data[$_csv_i] = preg_replace('/^' . $e . '(.*)' . $e . '$/s', '$1' , $_csv_data[$_csv_i]);<br />         $_csv_data[$_csv_i] = str_replace($e . $e, $e, $_csv_data[$_csv_i]);<br />     }<br />     return empty ($_line) ? false : $_csv_data;<br />}<br /><br />

------解决方案--------------------
fgetcsv的bug就是读取不了中文。。。
------解决方案--------------------
确实,感觉即使5.3了,对多字节的支持还是不是很好
------解决方案--------------------
其实是 php5.3 出问题了

Statement:
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