note 32247 added to function.explode

From: Date: Wed, 21 May 2003 14:52:17 +0000
Subject: note 32247 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-48741@lists.php.net to get a copy of this message
Your funcion ignores the last element of the CSV string. You have to add the line "$out[]=$word;" just befor the "return $out;". The function now looks like: function csv_explode2($str, $delim=',', $qual="\"") { $len=strlen($str); $inside=0; for ($i =0; $i<$len; $i++) { if ($str[$i]==$delim && !$inside) { $out[]=$word; $word=''; } else if ($str[$i]==$qual) { $inside=!$inside; } else { $word.=$str[$i]; } } $out[]=$word; return $out; } ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32247 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32247&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32247&report=yes

« previous php.notes (#48741) next »