[new] File_CSV class avaible

From: Date: Mon, 15 Apr 2002 19:39:56 +0000
Subject: [new] File_CSV class avaible
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-5533@lists.php.net to get a copy of this message
Hi, I just want to announce that the new class File_CSV is avaible. As the name suggests this class is for handling CSV files. The CSV (Comma Separated Values) is a common format for exporting/importing data in a simple way (well sometimes not so simple). Those files looks like: field1;field2;fields3 <data><separator><data><separator>.. Features: - CSV format autodetection - Treat the data as struct (fetching arrays or writing from arrays to/from the file) - Handle quoted and multiline fields - No need to use fopen/fclose - Very simple usage - Error detecting for broken CSV files Usage example: <?php require_once 'File/CSV.php'; $conf = File_CSV::discoverFormat('file.csv'); while ($fields = File_CSV('file.csv', $conf)) { print_r($fields); } ?> File_CSV vs fgetcsv(): I've implemented two different algoritms for parsing the data. One simple and fast and another more complex and slow. Depending on the format of the file and the type of line read, the class will automatically switch between them. So, in a simple CSV file with no things like quote or multine fields the speed difference between fgetcsv and the class is almost null (plus the fact that the class will properly handle quoted data, multiline data or errors if there is any). Status: I've tested it a lot with many different files, but you know the word is too big for being able to handle all the posibilities. Feedback on problems is appreciated. Tomas V.V.Cox PS.- Someone liking to develop a CSV driver for PEAR DB? ;-)

« previous php.pear.dev (#5533) next »