note 105776 deleted from function.fgets by danbrown

From: Date: Thu, 15 Sep 2011 17:09:15 +0000
Subject: note 105776 deleted from function.fgets by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183198@lists.php.net to get a copy of this message
Note Submitter: pligor at facebook dot com ---- There is a similar function inside fgetcsv documentation but it didn't work for a file containing UTF-8 greek characters. Therefore I created another one exploting fgets and strtok: <?php function csv2array($file, $delimiter) { if(($handle = fopen($file, "r")) === FALSE) { return false; } $token = "$delimiter\n\r"; $i = 0; while( ($string = fgets($handle)) !== false ) { $tok = strtok($string, $token); $j=0; while($tok !== false) { $data2DArray[$i][$j] = $tok; $tok = strtok($token); $j++; } $i++; } fclose($handle); return $data2DArray; } ?>

« previous php.notes (#183198) next »