Your browser (Internet Explorer 6) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.

Reading CSV file with newline as delimiter - PHP

I got some issues working with a CSV file with newline delimeter. I want to read the file and be able to process the content. I was so confused what the deliter would look like. After solving this I decided to share with everyone who has this same problem. I guess this would save somebody some from sleepless night. Wink

Below is the code that did the magic.

//CSV file
$csvFile = "upload/file.csv";

//read the content of the file
$contents = file_get_contents($csvFile);

//read the CSV file with delimiter
$data = str_getcsv($contents, "\r\n");

foreach($data as $row){
   //process the content here

Hope this helps someone.

comments powered by Disqus