We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

tylerhall on 08/07/06


Tagged

data import textmate read csv excel


Versions (?)


Who likes this?

13 people have marked this snippet as a favorite

yuconner
exor674
irdial
jmontano
halbtuerke
hudge
vali29
apocalip
JimiJay
cristianciofu
chucktrukk
romanos
sumandahal


Import CSV File


Published in: PHP 


This code reads a CSV file and extracts each item into the appropriate variable for processing.

  1. $handle = fopen("file.csv", 'r');
  2. while(($data = fgetcsv($handle, 1000, ",")) !== false)
  3. {
  4. list($col1, $col2, ...) = $data;
  5. }
  6. fclose($handle);

Report this snippet 

You need to login to post a comment.