note 113731 deleted from function.fgetcsv by tularis

From: Date: Fri, 22 Nov 2013 09:16:26 +0000
Subject: note 113731 deleted from function.fgetcsv by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197614@lists.php.net to get a copy of this message
Note Submitter: erilaksmonoadji at gmail dot com ---- <?php function readCsv($source = array('source'=>'', 'header_index'=>1, 'delimeters'=>',', 'oheader'=>array(), 'odata'=>array())) { if (($handle = fopen($source['source'], "r")) !== FALSE) { $x = 0; while (($data = fgetcsv($handle, 1000, $source['delimeters'])) !== FALSE) { if($x == $source['header_index']-1) { array_push($source['oheader'], $data); }else{ array_push($source['odata'], $data); } $x++; } fclose($handle); } return array( 'header'=>$source['oheader'], 'data'=>$source['odata'] ); } $source = array( 'source'=>'doc/ex.csv', 'header_index'=>1, 'delimeters'=>',', 'oheader'=>array(), 'odata'=>array() ); echo '<pre>'; print_r(readCsv($source)); echo '</pre>'; ?>

« previous php.notes (#197614) next »