Jump to content

Using Fgetcsv On Multiple Line Csv


MehItsMe

Recommended Posts

Hey all,

 

I've run into a bit of a problem when trying to use fgetcsv to dump the contents of a csv file into an array, in as much as fgetcsv stops after a line break.

I've been using fputcsv to add content to the file and every time I use fputcsv it adds a line break, hense my problem.

As you might have guessed from the time of this post (I'm in the uk) I've been trying to come up with a solution for this for quite a while; I'm pretty new to php as you might have gathered. :(

 

Code:

 

<?php

$fname=data.csv

$file=fopen($fname,"r");

$data=fgetcsv($file);

echo "$data[0] $data[1] $data[2]";

?>

 

The csv looks something like this:

adam,19

alex,16

andrew,24

etc...

I'm able to access the first 2 values with $data[0] and $data[1], but when I try and access anything after the first line break, I get undefined ofset errors.

 

If anyone could point me in the right direction to a solution for this problem I would be extremely greatful since I can't seem to find anything!!

 

In the mean time, I'm off to catch up on some sleep.

 

Cheers.

Link to comment
https://forums.phpfreaks.com/topic/221723-using-fgetcsv-on-multiple-line-csv/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.