PHP Classes

Excellent, but small bug found

Recommend this page to a friend!

      CSV Handler  >  All threads  >  Excellent, but small bug found  >  (Un) Subscribe thread alerts  
Subject:Excellent, but small bug found
Summary:Small bug found in parsing headers
Messages:3
Author:Lee Griffiths
Date:2013-05-14 19:52:32
Update:2013-12-17 13:39:01
 

  1. Excellent, but small bug found   Reply   Report abuse  
Picture of Lee Griffiths Lee Griffiths - 2013-05-14 19:52:32
Hi,

Thanks for building this straightforward and useful CSV handler.

I found a small bug. When I have spaces in column heading names like

'Contact email'

the commit button would not save changes for those columns. My columns names were delimited, but I guess this is an issue with extracting the column names

Changing the column names to something like

'Contact_email'

fixed this

Lee

  2. Re: Excellent, but small bug found   Reply   Report abuse  
Picture of Heart Heart - 2013-12-17 13:22:03 - In reply to message 1 from Lee Griffiths
This is because PHP converts the following characters in $_POST to an underscore (_)

chr(32) ( ) (space)
chr(46) (.) (dot)
chr(91) ([) (open square bracket)
chr(128) - chr(159) (various)

A fast workaround for this I added

$val = str_replace(" ","_", $val);

after

while(list($key,$val)=each($this->HeaderData)) {

(in Update function)

  3. Re: Excellent, but small bug found   Reply   Report abuse  
Picture of Heart Heart - 2013-12-17 13:39:01 - In reply to message 2 from Heart
Sent too fast...

Here is the my used update function

// Administration Area
function Update($key,$data) { //Updating Item "key" with "data" named array
$this->ReadCSV();
$headerdata_my = str_replace(" ","_", $this->HeaderData);
for($i=0;$i<count($this->ItemsList);$i++) {
if($this->ItemsList[$i][$this->DataKey]==$key){
while(list($key,$val)=each($headerdata_my)) {
$val_my = str_replace("_"," ", $val);
if(isset($data[$val])) $this->ItemsList[$i][$val_my]=$data[$val];
}
}
}
$this->WriteData();
return($this->ItemsList);
}