Search
 
SCRIPT & CODE EXAMPLE
 

PHP

read csv php

$file = "file.csv";

$csv            =   new SplFileObject($file);
$csv            ->  setFlags(SplFileObject::READ_CSV);
$csv            ->  setCsvControl(';');  //separator change if you need

foreach( $csv as $ligne){
    print_r($ligne);  //$ligne is an array
}
Comment

php open csv

    $csvFile = file('../somefile.csv');
    $data = [];
    foreach ($csvFile as $line) {
        $data[] = str_getcsv($line);
    }
Comment

read csv file in php

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

php read csv

<?php
ini_set('auto_detect_line_endings',TRUE);
$handle = fopen('/path/to/file','r');
while ( ($data = fgetcsv($handle) ) !== FALSE ) {
  //process the array in $data
  var_dump($data);
}
ini_set('auto_detect_line_endings',FALSE);
Comment

CSV File Read using PHP fgetcsv()

<?php
$CSVfp = fopen("fruits.csv", "r");
if ($CSVfp !== FALSE) {
    while (! feof($CSVfp)) {
        $data = fgetcsv($CSVfp, 1000, ",");
        print_r($data);
    }
}
fclose($CSVfp);
?>
Comment

PREVIOUS NEXT
Code Example
Php :: dynamic base url codeigniter 
Php :: htmlspecialchars_decode (PHP 5 = 5.1.0, PHP 7, PHP 8) htmlspecialchars_decode — Convert special HTML entities back to characters 
Php :: laravel execute command from terminal 
Php :: php filters 
Php :: php array loop 
Php :: Adding data to a laravel collection 
Php :: implode array keys in php 
Php :: create database from migration laravel for all 
Php :: laravel automatically generate unique username 
Php :: php day of week full name 
Php :: how to pass bearer token in swagger in laravel 
Php :: nginx 404 not found laravel 
Php :: how to get attribute value in xml using php 
Php :: features of PHP7 
Php :: laravel find by field 
Php :: how to write javascript inside php 
Php :: how to make zip in php by multiple files 
Php :: php week of a date 
Php :: php html to text 
Php :: connect another database in wordpress 
Php :: php return function result to variable 
Php :: cache an array 
Php :: laravel log 
Php :: SPA and keep some of the Laravel pages you need to have a route like this 
Php :: laravel eloquent get specific columns using with function 
Php :: file upload permission in php 
Php :: custom rule laravel validation 
Php :: php how to connect to db using PDO 
Php :: ubuntu 7.2 deleted php 
Php :: file upload codeigniter 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =