Skip to content

Instantly share code, notes, and snippets.

@mig1098
Created March 19, 2019 17:10
Show Gist options
  • Save mig1098/a1898ceec4ee843f87571be11d82f9fe to your computer and use it in GitHub Desktop.
Save mig1098/a1898ceec4ee843f87571be11d82f9fe to your computer and use it in GitHub Desktop.
Read csv files from csv. PHP
<?php
//tmp_name from input file
//@param array $tmp
//@return array
function leercsv($tmp){
$arrayData = array();
if(!($handle = @fopen ($tmp, 'rb'))){
throw new \Exception('Error en la carga del fichero');
}else{
$row = 1;
while (($data = fgetcsv($handle, 10000, $sp, '"')) != FALSE){
if($row == 1){ $row++; continue; }
if($data[0]!= '' && $data[1] != ''){
$arrayData[] = $data;
}
}
}
return $arrayData;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment