note 101255 deleted from function.fgetcsv by danbrown

From: Date: Mon, 06 Dec 2010 17:59:15 +0000
Subject: note 101255 deleted from function.fgetcsv by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-174665@lists.php.net to get a copy of this message
Note Submitter: Danielb ---- 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.

« previous php.notes (#174665) next »