jcadima
7/21/2017 - 8:47 PM

Read csv data

Read csv data

https://stackoverflow.com/questions/9139202/how-to-parse-a-csv-file-using-php


<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title></title>

  <link rel="stylesheet" href="css/main.css">
</head>

<body>

<?php
// $f = fopen("test.csv", "r");


echo '<hr>'; 

$csv = array_map('str_getcsv', file('samplecsv2.csv'));

$row = 1;
if (($handle = fopen("samplecsv2.csv", "r")) !== FALSE) {
  while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $num = count($data);
    echo "<p> $num fields in line $row: <br /></p>\n";
    $row++;
    for ($c=0; $c < $num; $c++) {
        echo '<div>=> '  . $data[$c] . "</div>\n";
    }
    echo '<hr>' ;
  }
  fclose($handle);
}

echo '<pre>'; 
print_r($csv) ;
echo '</pre>';


?>


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  <script src="js/scripts.js"></script>
</body>

</html>