note 69899 added to function.split

From: Date: Mon, 25 Sep 2006 18:54:02 +0000
Subject: note 69899 added to function.split
Groups: php.notes 
Request: Send a blank email to php-notes+get-117649@lists.php.net to get a copy of this message
There is an error with my note dated 14 February 2006. The function as shown does not properly handle CSV data in the following case: 1,"foo",,"bar" this should get split to: { [0] => 1 [1] => foo [2] => [3] => bar } (the blank entry 2 is because of the doubled commas). However, in the function listed, entry 2 would get ignored by the function because it's interpreted as a unitary delimiter and ignored as containing valid data. Yet it DOES contain valid data, it indicates a blank field value. To fix this, replace this line in the function: if ((strlen($val)-$delimlen-$delimlen) >= 1) { with this: if ((strlen($val)-$delimlen) >= 1) { This way, entries at the end of lines or between "foo","bar" will get properly parsed, but "foo",,"bar" will still be OK. ---- Server IP: 66.163.161.117 Probable Submitter: 67.103.150.234 ---- Manual Page -- http://www.php.net/manual/en/function.split.php Edit -- https://master.php.net/note/edit/69899 Del: integrated -- https://master.php.net/note/delete/69899/integrated Del: useless -- https://master.php.net/note/delete/69899/useless Del: bad code -- https://master.php.net/note/delete/69899/bad+code Del: spam -- https://master.php.net/note/delete/69899/spam Del: non-english -- https://master.php.net/note/delete/69899/non-english Del: in docs -- https://master.php.net/note/delete/69899/in+docs Del: other reasons-- https://master.php.net/note/delete/69899 Reject -- https://master.php.net/note/reject/69899 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117649) next »