note 95421 added to function.fgetcsv
| From: | MarcoMoscher at osu1 dot php dot net | Date: | Sat, 02 Jan 2010 21:23:49 +0000 |
| Subject: | note 95421 added to function.fgetcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164539@lists.php.net to get a copy of this message | ||
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;
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 84.135.78.121
----
Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php
Edit -- https://master.php.net/note/edit/95421
Del: integrated -- https://master.php.net/note/delete/95421/integrated
Del: useless -- https://master.php.net/note/delete/95421/useless
Del: bad code -- https://master.php.net/note/delete/95421/bad+code
Del: spam -- https://master.php.net/note/delete/95421/spam
Del: non-english -- https://master.php.net/note/delete/95421/non-english
Del: in docs -- https://master.php.net/note/delete/95421/in+docs
Del: other reasons-- https://master.php.net/note/delete/95421
Reject -- https://master.php.net/note/reject/95421
Search -- https://master.php.net/manage/user-notes.php