mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 08:36:39 +00:00
Merge branch 'master' of https://github.com/williamknauss/php-parsecsv into start-testing
This commit is contained in:
@@ -666,9 +666,16 @@ class parseCSV {
|
|||||||
$was_enclosed = false;
|
$was_enclosed = false;
|
||||||
$strlen = strlen($data);
|
$strlen = strlen($data);
|
||||||
|
|
||||||
|
// force the parser to process end of data as a character (false) when
|
||||||
|
// data does not end with a line feed or carriage return character.
|
||||||
|
$lch = $data{$strlen-1};
|
||||||
|
if ($lch != "\n" && $lch != "\r") {
|
||||||
|
$strlen++;
|
||||||
|
}
|
||||||
|
|
||||||
// walk through each character
|
// walk through each character
|
||||||
for ( $i=0; $i < $strlen; $i++ ) {
|
for ( $i=0; $i < $strlen; $i++ ) {
|
||||||
$ch = $data{$i};
|
$ch = ( isset($data{$i}) ) ? $data{$i} : false ;
|
||||||
$nch = ( isset($data{$i+1}) ) ? $data{$i+1} : false ;
|
$nch = ( isset($data{$i+1}) ) ? $data{$i+1} : false ;
|
||||||
$pch = ( isset($data{$i-1}) ) ? $data{$i-1} : false ;
|
$pch = ( isset($data{$i-1}) ) ? $data{$i-1} : false ;
|
||||||
|
|
||||||
@@ -734,9 +741,9 @@ class parseCSV {
|
|||||||
$enclosed = false;
|
$enclosed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// end of field/row
|
// end of field/row/csv
|
||||||
}
|
}
|
||||||
elseif ( ($ch == $this->delimiter || $ch == "\n" || $ch == "\r") && !$enclosed ) {
|
elseif ( ($ch == $this->delimiter || $ch == "\n" || $ch == "\r" || $ch === false) && !$enclosed ) {
|
||||||
$key = ( !empty($head[$col]) ) ? $head[$col] : $col ;
|
$key = ( !empty($head[$col]) ) ? $head[$col] : $col ;
|
||||||
$row[$key] = ( $was_enclosed ) ? $current : trim($current) ;
|
$row[$key] = ( $was_enclosed ) ? $current : trim($current) ;
|
||||||
$current = '';
|
$current = '';
|
||||||
@@ -744,7 +751,7 @@ class parseCSV {
|
|||||||
$col++;
|
$col++;
|
||||||
|
|
||||||
// end of row
|
// end of row
|
||||||
if ( $ch == "\n" || $ch == "\r" ) {
|
if ( $ch == "\n" || $ch == "\r" || $ch === false ) {
|
||||||
if ( $this->_validate_offset($row_count) && $this->_validate_row_conditions($row, $this->conditions) ) {
|
if ( $this->_validate_offset($row_count) && $this->_validate_row_conditions($row, $this->conditions) ) {
|
||||||
if ( $this->heading && empty($head) ) {
|
if ( $this->heading && empty($head) ) {
|
||||||
$head = $row;
|
$head = $row;
|
||||||
|
|||||||
Reference in New Issue
Block a user