Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,45 @@ class csv
{

private $m_csv;

private $m_count;

private $m_index;

private $m_rows;

public $delimiter = ',';
public $quote = '"';

private function row()
{
$row = [];
$column = '';
while ($this->m_index < $this->m_count)
{
$character = $this->m_csv[$this->m_index++];
if ($character == '"')
if ($character == $this->quote)
{
while ($this->m_index < $this->m_count)
{
$character = $this->m_csv[$this->m_index++];
if ($character == '"')
if ($character == $this->quote)
{
/*
* If a double quote is found in a double quoted column then the following character must be:
* If a double quote is found in a double-quoted column then the following character must be:
*
* - A double quote which is the second character of an escaped double quote.
* - A comma which is the end of the column.
* - A CR, CR LF or LF which is the end of the column and the end of the row.
* - An EOF which is the end of the column, the end of the row and the end of the file.
* - A CR, CR LF, or LF which is the end of the column and the end of the row.
* - An EOF which is the end of the column, the end of the row, and the end of the file.
*
* Anything else is an error.
*/
if ($this->m_index < $this->m_count)
{
$character = $this->m_csv[$this->m_index++];
if ($character == '"')
if ($character == $this->quote)
{
$column .= $character;
}
else if ($character == ',')
else if ($character == $this->delimiter)
{
$row[] = $column;
$column = '';
Expand Down Expand Up @@ -91,7 +91,7 @@ private function row()
{
while (true)
{
if ($character == ',')
if ($character == $this->delimiter)
{
$row[] = $column;
$column = '';
Expand Down