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 :: request get query string laravel 
Php :: difference of two dates in seconds php 
Php :: php unset array key 
Php :: laravel date between 
Php :: test if php is installed 
Php :: PHP strtotime() Function 
Php :: How do I make a redirect in PHP? 
Php :: convert date php 
Php :: woocommerce order get_data() 
Php :: name csrf token laravel mismatch 
Php :: php array all keys empty 
Php :: php shutdown function 
Php :: php get current time and date 
Php :: php var exists 
Php :: laravel-socialite-invalidstateexception 
Php :: how to get woocommerce category image 
Php :: how add field to table by another migration in laravel 
Php :: php get first 10 elements of array 
Php :: if is alphabet php 
Php :: larave artisan command run in web 
Php :: foreach loop 1-100 php 
Php :: how to check mobile or desktop in php 
Php :: session variable in laravel 
Php :: cron run 1 time 
Php :: codeigniter table list 
Php :: eloquent limit vs take 
Php :: laravel wher in 
Php :: clear array php 
Php :: how to display image in wordpress 
Php :: woocommerce profile photo upload 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =