A simple CSV file reader.

Emulates an array of records (arrays), implimented as an Iterator, so can be used in a foreach statements.

  • If your CSV file has headers (the default), then the keys of the returned array will be the header values.
  • You can also specify a different field delimiter, for example ("\t") for tabs.
  • Use rewind to reset to the top of the file.
  • The header record is NEVER returned as a record. The first iteration will be the first record in the file, excluding the header record if specified.
public __construct(string $fileName, bool $headerRow = true, string $delimiter = ',')
public __destruct()
public current() : array
public key() : int
public next() : void
public rewind() : void
public setHeaders(array $headers) : self

You can specify headers if your file does not include them. The headers will be used as the key in the returned associative array for each record.

    public valid() : bool
    private array $current
    private string $delimiter
    private $fh
    private string $fileName
    private bool $headerRow
    private array $headers
    private int $index
    private closeFile() : self
    © 2020 Bruce Wells
    Search Namespaces \ Classes
    ConfigurationNumbers (0-9.) only