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 :: HTML5 Date Valu In PHP 
Php :: laravel mass update 
Php :: laravel denny request by ip 
Php :: remove element from xml on php 
Php :: php random characters 
Php :: php echo selected option 
Php :: php curl Content-Length 
Php :: push key value array php 
Php :: composer_update 
Php :: Notice: Undefined variable: _SESSION in C:xampphtdocspracticeheader.php on line 7 
Php :: ternary operator for three conditions in php 
Php :: laravel where multiple conditions on single colmn 
Php :: with in laravel 
Php :: laravel collection push 
Php :: php string to uppercase 
Php :: laravel 6 auth 
Php :: php endwhile 
Php :: htmlspecialchars_decode (PHP 5 = 5.1.0, PHP 7, PHP 8) htmlspecialchars_decode — Convert special HTML entities back to characters 
Php :: how to change woocommerce read more text 
Php :: laravel raw query join many to many 
Php :: laravel validation array input 
Php :: laravel has one 
Php :: tableau aléatoire php 
Php :: gd php extension 
Php :: how to make zip in php by multiple files 
Php :: passing parameters with route keyword in blade laravel 
Php :: http_response_code 
Php :: PHP filter_var() Function 
Php :: php print all woocommerce products 
Php :: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =