I use this code to get the number of columns from a CSV file:
$this->dummy_file_handler = fopen($this->config['file'],'r');
if ($dataset =fgetcsv($this->dummy_file_handler))
{
$this->number_of_columns = count($dataset);
}
It works fine unless the file is exported with Excel for Mac 2011 since the new line character is then Classic Mac (CR) which fgetcsv
doesn't recognize.
If I manually change the newline from Classic Mac (CR) to Unix (LR), then it works, but I need this to be automated.
How can I make fgetcsv
recognize the Classic Mac (CR) new line character?
From the manual:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With