note 41483 added to function.fgetcsv

From: Date: Mon, 12 Apr 2004 04:30:16 +0000
Subject: note 41483 added to function.fgetcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-68005@lists.php.net to get a copy of this message
The following modification will hide the unnecessary delimiter in the array that is returned when fgetcsvfromline is called. function fgetcsvfromline ($line, $columnCount, $delimiterChar = ',', $enclosureChar = '"') { global $regExpSpecialChars; $matches = array(); $delimiterChar = strtr($delimiterChar, $regExpSpecialChars); $enclosureChar = strtr($enclosureChar, $regExpSpecialChars); $cutpoint = strlen($delimiterChar)+1; $regExp = "/^"; for ($i = 0; $i < $columnCount; $i++) { $regExp .= $enclosureChar.'?(.*?)'.$enclosureChar.'?'.$delimiterChar; } $regExp = substr($regExp,0,-$cutpoint).'/'; if (preg_match($regExp, $line, $matches)) { return $matches; } return 0; } === If you were getting [0] => "Ma"rk","Bergeron","rocks","12345,"times" [1] => " [2] => Ma"rk [3] => " ..etc You will now get [0] => "Ma"rk","Bergeron","rocks","12345,"times" [1] => Ma"rk ...etc ---- Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41483 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41483&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41483&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#68005) next »