linux中fgetcsv取得的数组元素为空字符串的解决方法
分享一篇关于linux中fgetcsv取得的数组元素为空字符串的解决方法的教程,有需要的朋友可以参考一下.
使用CSV导入数据的时候,我们通常用的是Windows系统,使用GBK在Windows的Excel中编辑.但服务器上,很多使用Linux服务器,源程序使用UTF-8,这样很容易产生字符编码的问题.如果仅仅将CSV文件转码为UTF-8,这样在Windows服务器上没有问题,而在RedHat5.5上,用fgetcsv取得的数组中,如果某列的内容是中文,则该列对应的数组元素为空字符串,而英文则正常.这时,需要设置区域如下:
setlocale(LC_ALL, 'zh_CN.UTF-8');
PHP实例代码如下:
// 上传的CSV文件,通常是用Excel编辑的GBK编码,
// 而源代码是UTF-8,需要进行转码处理
file_put_contents($new_file, iconv('GBK', 'UTF-8', file_get_contents($new_file))); //ini_set('auto_detect_line_endings', true); // 设置区域:简体中文,UTF-8编码 setlocale(LC_ALL, 'zh_CN.UTF-8'); // 打开CSV文件 $handle = fopen($new_file, 'r'); // 取出列头 $data_heads = fgetcsv($handle);
本文地址:
转载随意,但请附上文章地址:-)

Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

AI Hentai Generator
Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

Heiße Werkzeuge

Notepad++7.3.1
Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version
Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1
Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6
Visuelle Webentwicklungstools

SublimeText3 Mac-Version
Codebearbeitungssoftware auf Gottesniveau (SublimeText3)
