MehItsMe Posted December 15, 2010 Share Posted December 15, 2010 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 More sharing options...
PFMaBiSmAd Posted December 15, 2010 Share Posted December 15, 2010 The php.net documentation, see this link - fgetcsv , contains an example showing how to loop through the contents of a file. Link to comment https://forums.phpfreaks.com/topic/221723-using-fgetcsv-on-multiple-line-csv/#findComment-1147544 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.