diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 1c9311e..790df4a 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -626,7 +626,10 @@ class parseCSV { $current .= $ch; $i++; } elseif ($nch != $this->delimiter && $nch != "\r" && $nch != "\n") { - for ($x = ($i + 1);isset($data{$x}) && ltrim($data{$x}, $white_spaces) == ''; $x++) {} + $x = $i + 1; + while (isset($data{$x}) && ltrim($data{$x}, $white_spaces) == '') { + $x++; + } if ($data{$x} == $this->delimiter) { $enclosed = false; $i = $x; @@ -814,7 +817,7 @@ class parseCSV { $this->file = $file; } - if (preg_match('/\.php$/i', $file) && preg_match('/<\?.*?\?>(.*)/ims', $data, $strip)) { + if (preg_match('/\.php$/', $file) && preg_match('/<\?.*?\?>(.*)/ms', $data, $strip)) { $data = ltrim($strip[1]); } @@ -925,12 +928,14 @@ class parseCSV { $op = $capture[2]; $value = $capture[3]; - if (preg_match('/^([\'\"]{1})(.*)([\'\"]{1})$/i', $value, $capture)) { + if (preg_match('/^([\'\"]{1})(.*)([\'\"]{1})$/', $value, $capture)) { if ($capture[1] == $capture[3]) { - $value = $capture[2]; - $value = str_replace("\\n", "\n", $value); - $value = str_replace("\\r", "\r", $value); - $value = str_replace("\\t", "\t", $value); + $value = strtr($capture[2], array( + "\\n" => "\n", + "\\r" => "\r", + "\\t" => "\t", + )); + $value = stripslashes($value); } } @@ -969,11 +974,10 @@ class parseCSV { * @return true of false */ protected function _validate_offset($current_row) { - if ($this->sort_by === null && $this->offset !== null && $current_row < $this->offset) { - return false; - } - - return true; + return + $this->sort_by !== null || + $this->offset === null || + $current_row >= $this->offset; } /** @@ -1153,6 +1157,7 @@ class parseCSV { } // remove delimiter and its line-end (the data param is by-ref!) + /** @noinspection CallableParameterUseCaseInTypeContextInspection */ $data_string = substr($data_string, $pos); return true; } @@ -1178,6 +1183,7 @@ class parseCSV { $pch = isset($data{$i - 1}) ? $data{$i - 1} : false; // open and closing quotes + $is_newline = ($ch == "\n" && $pch != "\r") || $ch == "\r"; if ($ch == $enclosure) { if (!$enclosed || $nch != $enclosure) { $enclosed = $enclosed ? false : true; @@ -1186,7 +1192,7 @@ class parseCSV { } // end of row - } elseif (($ch == "\n" && $pch != "\r" || $ch == "\r") && !$enclosed) { + } elseif ($is_newline && !$enclosed) { if ($current_row >= $search_depth) { $strlen = 0; $to_end = false;