Windows csv和mac csv有什么区别?

编程入门 行业动态 更新时间:2024-10-28 10:21:49
本文介绍了Windows csv和mac csv有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用此代码解析csv文件

I am trying to parse a csv file using this code

if (($handle = fopen($csvFilePath, "r")) !== FALSE) { $c=0; $string=""; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if($c>0) { if(($data[$email]!="") and ($data[$firstname]!="") and ($data[$lastname]!="")) { $string.='(1,'; $string.="'".$data[$email]."',"; $string.="'".$data[$firstname]."',"; $string.="'".$data[$lastname]."',"; $string.="'".Yii::app()->params['clientimporttext']."'"; $string.='),'; } } $c++; } fclose($handle); }

与Windows csv一起正常工作. 但是当我从Mac创建一个csv并解析它不起作用时((它无法识别行尾)),

It is working fine with windows csv. but when i create a csv from mac and parse that it is not working.( it cant identify end of line),

当我用Mac打开相同的Windows csv并使用相同的代码进行解析时,它也不起作用. 但是当我将其另存为Windows csv时.再次起作用. 那么Mac csv和Windows csv之间的区别到底是什么? 这两个分隔符是否不同? 我应该如何更改代码才能使其同时工作?

also when i open the same windows csv with mac and parse using the same code it is not working. but when i save it as windows csv. it again works. so actually wat is the difference between mac csv and windows csv? Is the delimiter different for these two? How should i change the code to make it work with both?

推荐答案

答案在PHP文档注释中:

The answer is in the PHP doc comments:

be2.php/manual/zh/function .fgetcsv.php

注意:如果在读取Macintosh计算机上或由Macintosh计算机创建的文件时PHP无法正确识别行尾,则启用 auto_detect_line_endings 运行时配置选项可能有助于解决问题.

Note: If PHP is not properly recognizing the line endings when reading files either on or created by a Macintosh computer, enabling the auto_detect_line_endings run-time configuration option may help resolve the problem.

问题在于Windows和类unix的计算机(如您的Mac)上的行尾之间的区别:windows ='\r\n'和unix = '\n'

The problem is in the difference between line endings on Windows and unix-like machines (as your mac is): windows ='\r\n' and unix = '\n'

解决方案:在打开文件之前添加以下行:

The solution: add this line before opening the file:

ini_set('auto_detect_line_endings',TRUE);

更多推荐

Windows csv和mac csv有什么区别?

本文发布于:2023-10-08 02:19:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471227.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   Windows   csv   mac

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!