Hello
My problem is about "end of line" in text files uploaded from MAC OS which are to be treated on server with fgetcsv function.
My PHP application have to import a CSV text file.
1) The file is uploaded.
2) The PHP script opens it and reads it with fgetcsv
A DOS file uploaded on a DOS/WIN server is working fine.
A DOS file uploaded on a UNIX server is working fine.
A MAC file uploaded on a DOS/WIN server is not working correctly.
A MAC file uploaded on a UNIX server is not working correctly.
I found following "end of line" classic rules :
MAC : 0x0D = CR = \r
*nix : 0x0A = LF = \n
DOS : 0x0D,0x0A = CRLF = \r\n
- fgets / fgetcsv are reading each line until \n is found (or max buffer size). That's why it's not working with Mac files.
- PHP Server can be running Windows or Unixes. I know the OS in the script.
- Uploaded file can come from Windows, Mac or even Unixes. I can ask user with radio buttons to know
my code is (nearly):
<?
...
$f = fopen ($importfile, "r");
while ($data = fgetcsv($f, 2048, $separator)) {
...
}
fclose ($f);
...
?>
My Question is : does anybody knows how to cleanly solve this problem (with the smallest / fastest code and no new files / arrays to be created). What I need is to be able to deal with MAC files ;-)
Thank you
Aaaxl