CSV is a type of file. It means Comma Separated Values. Spreadsheets software like Excel will offer you the opportunity to save files with the CSV extension. It is a big challenge for web developers to write a lengthy code to parse these files for different purposes, may be for databases like MySql.
How to Process a CSV File in PHP
PHP has a function called fgetcsv that allows you to place the values from a comma separated value (csv) file into an array. The function reads one line (row) at a time, so it must be placed within a loop in order to process an entire file.
The function arguments are as follows: resource, length of line, delimiter, enclosure and escape. You should specify the length to be longer than the longest line. Use the delimiter argument if your file uses something other than a comma. If your data is enclosed in single and double quotes, specify that in the enclosure argument. The escape value defaults to “new line”, but can be specified as something else.
Chip CSV Parser
I have written a CSV Parser in PHP, which is ready to download for your different web projects. Some Features of PHP CSV Parser Class are,
- It can “Read” CSV files
- It can “Write” CSV files
- Full control to use CSV delimiter
Demo / Download PHP CSV Parser Class
Click Here to see online demo, features and download link for PHP CSV Parser class.