Read CSV file using php

I believe, it’s pretty simple and it’s widely used. Yes,  CSV file is widely used for data importing or exporting in web application specially application built using php. So sometimes it’s needed to create a CSV file from data and vice-versa.  All version of PHP has a nice built in method by which you can read a csv file(comma, tab, semicolon delimited) easily. Try with the following code which i taken from php manual directly without any modification –

  $row = 1;
  $handle = fopen("test.csv", "r");
      while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
      $num = count($data);
      echo "<p> $num fields in line $row: <br /></p>\n";
          for ($c=0; $c < $num; $c++) {
          echo $data&#91;$c&#93; . "<br />\n";

Hope this can help you!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.