Friday, November 2, 2007

How to parse CSV files in PHP

Parsing CSV files in PHP



CSV - comma separated values. Values in a CSV file are separated by comma.

Eg:

name, score
john, 10
brian, 5
jane, 8

So how do you get values from a CSV file in PHP? The easiest way to is to use PHP function fgetcsv . Read the documentation about this function, and there is also an easy example there.

Using CSV files, is a good option if you don't have access or you don't want to use a database. After you parse the CSV file, you can get the values in an array, and then display them any way you want on the web page.

PHP parse csv file

No comments: