diff --git a/src/PhpSpreadsheet/Reader/Csv.php b/src/PhpSpreadsheet/Reader/Csv.php index 4713409881..2b250872be 100644 --- a/src/PhpSpreadsheet/Reader/Csv.php +++ b/src/PhpSpreadsheet/Reader/Csv.php @@ -242,27 +242,26 @@ function ($sum, $value) use ($median) { */ private function getNextLine($line = '') { - // Get the next line in the file - $newLine = fgets($this->fileHandle); + do { + // Get the next line in the file + $newLine = fgets($this->fileHandle); - // Return false if there is no next line - if ($newLine === false) { - return false; - } + // Return false if there is no next line + if ($newLine === false) { + return false; + } - // Add the new line to the line passed in - $line = $line . $newLine; + // Add the new line to the line passed in + $line = $line . $newLine; - // Drop everything that is enclosed to avoid counting false positives in enclosures - $enclosure = '(?escapeCharacter, '/') . ')' - . preg_quote($this->enclosure, '/'); - $line = preg_replace('/(' . $enclosure . '.*' . $enclosure . ')/Us', '', $line); + // Drop everything that is enclosed to avoid counting false positives in enclosures + $enclosure = '(?escapeCharacter, '/') . ')' + . preg_quote($this->enclosure, '/'); + $line = preg_replace('/(' . $enclosure . '.*' . $enclosure . ')/Us', '', $line); - // See if we have any enclosures left in the line - // if we still have an enclosure then we need to read the next line as well - if (preg_match('/(' . $enclosure . ')/', $line) > 0) { - $line = $this->getNextLine($line); - } + // See if we have any enclosures left in the line + // if we still have an enclosure then we need to read the next line as well + } while (preg_match('/(' . $enclosure . ')/', $line) > 0); return $line; }