How To Read CSV File Using PHP

It's only fair to share...Share on Facebook0Share on Google+0Tweet about this on Twitter0Share on LinkedIn0Pin on Pinterest0Digg thisShare on StumbleUpon0

csv php
One of my fresher follower ask me to provide the script for CSV read using PHP. It’s a basic script and required most of the fresher who started their career in PHP. This tutorial will help them to read CSV file using PHP. PHP has in-built function to read CSV file. The function is fgetcsv(). This function accepts CSV file, reads CSV data and converts it into array.

$handle - CSV file resource data.
$length - Must be greater than the longest line (in characters) to be found in the CSV file (allowing for trailing line-end characters). It became optional in PHP 5. Omitting this parameter (or setting it to 0 in PHP 5.1.0 and later) the maximum line length is not limited, which is slightly slower.
$delimiter - The optional delimiter parameter sets the field delimiter (one character only).
$enclosure - The optional enclosure parameter sets the field enclosure character (one character only).
$escape - The optional escape parameter sets the escape character (one character only).


 Code for CSV read:

If you want to insert csv records in database then check my previous article Upload CSV and Insert into Database Using PHP.


Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">