HEX
Server: LiteSpeed
System: Linux d8 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User: wbwebdes (3015)
PHP: 8.1.31
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/wbwebdes/domains/mailing.wb-cloud.nl/public_html/admin/CsvReader.php
<?php

class CsvReader
{
    private $fh;
    private $delimiter;
    private $totalRows;

    const ENCLOSURE = '"';
    const ESCAPE = "\0";

    /**
     * Constructor.
     * Setting auto_detect_line_endings is needed to allow CR as line separator.
     * Read all rows from the file to get the count of rows ignoring empty lines.
     */
    public function __construct($filename, $delimiter)
    {
        $this->fh = fopen($filename, 'r');
        $this->delimiter = $delimiter;
        $this->totalRows = 0;

        while ($row = fgetcsv($this->fh, 0, $this->delimiter, self::ENCLOSURE, SELF::ESCAPE)) {
            if ($row[0] !== null) {
                ++$this->totalRows;
            }
        }
        rewind($this->fh);
    }

    /**
     * Return the number of rows in the file.
     *
     * @return int
     */
    public function totalRows()
    {
        return $this->totalRows;
    }

    /**
     * Return the result of calling fgetcsv() ignoring empty lines.
     *
     * @return array|false|null
     */
    public function getRow()
    {
        do {
            $row = fgetcsv($this->fh, 0, $this->delimiter, self::ENCLOSURE, SELF::ESCAPE);
        } while ($row && $row[0] === null);

        return $row;
    }
}