note 95421 deleted from function.fgetcsv by danbrown

From: Date: Sun, 03 Jan 2010 00:59:58 +0000
Subject: note 95421 deleted from function.fgetcsv by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-164544@lists.php.net to get a copy of this message
Note Submitter: Marco Moscher ---- I was free to modifie the class from jaimthorn http://www.php.net/manual/de/function.fgetcsv.php#88616 My problem was/is that i´ve got many line breaks in my spreadsheet fields. As result of this i had many line breaks in my csv-file, witch let php thinks, that it is a new coloum/line in the spreadsheet -> Epic Fail ! =) So i modified the class a little bit and maybe some one need it also like me. Sry for my bad english. Here it goes, only the changes you´ve to change <?php ... class PaperPear_CSVParser { ... private $header_index = ''; private $current_row_index = ''; private $first_try_gone = false; private function processHeader() { .... $this->header_index = $nIndex; } //read the next CSV entry public function getNext() { //this is a basic read, you will likely want to change this to accomodate what //you are using for CSV parameters (tabs, encapsulation, etc). if (($saValues = fgetcsv($this->m_fp,'',"#")) !== false) { //$this->m_saValues = $saValues; $anz = count($saValues); //$current_row_index .= $anz; //Text anfügen if ($anz == 1 && $this->first_try_gone) { $this->m_saValues[count($this->m_saValues)-1] .= "<br>".$saValues[0]; }else if ($anz > 1 && $this->first_try_gone ) { $this->m_saValues[count($this->m_saValues)-1] .= "<br>".$saValues[0]; array_shift($saValues); $this->m_saValues = array_merge($this->m_saValues,$saValues); $this->current_row_index = $this->current_row_index+$anz-1; }else if (!$this->first_try_gone) { $this->m_saValues = $saValues; $this->current_row_index = $this->current_row_index+$anz; } $this->first_try_gone = true; if ( $this->current_row_index != $this->header_index ) { $this->getNext(); }else{ $this->current_row_index = ''; $this->first_try_gone = false; } return true; } return false; } } ?>

« previous php.notes (#164544) next »