note 41483 deleted from function.fgetcsv by cmb

From: Date: Sun, 16 Jun 2019 08:07:59 +0000
Subject: note 41483 deleted from function.fgetcsv by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211264@lists.php.net to get a copy of this message
Note Submitter: dawa at did-it dot com ---- The following modification will hide the unnecessary delimiter in the array that is returned when fgetcsvfromline is called. <?php 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

« previous php.notes (#211264) next »