note 101255 added to function.fgetcsv

From: Date: Mon, 06 Dec 2010 01:29:17 +0000
Subject: note 101255 added to function.fgetcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-174635@lists.php.net to get a copy of this message
A note for anyone trying to use aleske's RFC4180 compliant code, there are a couple bugs or missing features. Firstly the line in array_to_csvstring() that reads: || (stripos($item, $CSV_LINEBREAK !== false))) { should be: || (stripos($item, $CSV_LINEBREAK) !== false)){ Secondly the csvstring_to_array() only works if you feed it a full line, which is impractical if your CSV data contains newline characters. The way around this is to declare a new array at the top of the function: $lines = array(); Then about a third of the way down he has: break; Replace that with: $lines[] = $o; $o = array(); $num = 0; continue; And at the end of the function return $lines, not $o. Now you will be able to feed the entire CSV file as $string, and get the full array back. ---- Server IP: 69.147.83.197 Probable Submitter: 202.172.125.63 ---- Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php Edit -- https://master.php.net/note/edit/101255 Del: integrated -- https://master.php.net/note/delete/101255/integrated Del: useless -- https://master.php.net/note/delete/101255/useless Del: bad code -- https://master.php.net/note/delete/101255/bad+code Del: spam -- https://master.php.net/note/delete/101255/spam Del: non-english -- https://master.php.net/note/delete/101255/non-english Del: in docs -- https://master.php.net/note/delete/101255/in+docs Del: other reasons-- https://master.php.net/note/delete/101255 Reject -- https://master.php.net/note/reject/101255 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174635) next »