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 :: how to include file in laravel blade 
Php :: convert array into , separated string in php 
Php :: how to get attachments to emails php 
Php :: wp image size name 
Php :: php check if all array values are the same 
Php :: associate laravel 
Php :: session_start cookie lifetime 
Php :: how to show image in laravel 
Php :: laravel use global variable in model 
Php :: php http errorcode 
Php :: php time() 
Php :: wpml get site url 
Php :: php check if checkbox isset 
Php :: sort array php by key 
Php :: php send http request 
Php :: php associative array join key values 
Php :: laravel db table get one columns value 
Php :: php send json post 
Php :: install laravel on windows 
Php :: slugify text in php 
Php :: remove colon and white space in a string by php 
Php :: get all sort by laravel 
Php :: send json reponse php 
Php :: laravel make password 
Php :: one lin if statement php 
Php :: php append n time pattern to string 
Php :: php get all array keys in json 
Php :: php unit 
Php :: get request header codeingiter3 
Php :: wordpress plugin functions exist 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =