note 62524 added to function.fgetcsv

From: Date: Thu, 02 Mar 2006 14:16:23 +0000
Subject: note 62524 added to function.fgetcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-104705@lists.php.net to get a copy of this message
For those of you who need to get CSV data from a single line of quoted CSV (comma delimited) values (that may have commas in the data), use this: <? function csv_string_to_array($str){ $expr="/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/"; $results=preg_split($expr,trim($str)); return preg_replace("/^\"(.*)\"$/","$1",$results); } $str=<<<EOF "testing, stuff, here","is testing ok",200,456 EOF; print_r(csv_string_to_array($str)); ?> ---- Server IP: 64.71.164.2 Probable Submitter: 209.70.1.59 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php Edit -- http://master.php.net/note/edit/62524 Del: integrated -- http://master.php.net/note/delete/62524/integrated Del: useless -- http://master.php.net/note/delete/62524/useless Del: bad code -- http://master.php.net/note/delete/62524/bad+code Del: spam -- http://master.php.net/note/delete/62524/spam Del: non-english -- http://master.php.net/note/delete/62524/non-english Del: in docs -- http://master.php.net/note/delete/62524/in+docs Del: other reasons-- http://master.php.net/note/delete/62524 Reject -- http://master.php.net/note/reject/62524 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#104705) next »