stream_get_line example

public function __construct($filename)
    {
        $this->stream = fopen($filename, 'rb');
        if (!$this->stream) {
            throw new Exception('Can not open stream. File: ' . $filename);
        }

        $this->position = 0;
        $this->count = 0;

        while (!feof($this->stream)) {
            stream_get_line($this->stream, 1000000, ";\n");
            ++$this->count;
        }

        $this->rewind();
    }

    public function __destruct()
    {
        if ($this->stream !== null) {
            fclose($this->stream);
        }
    }

    private function _read()
    {
        if (feof($this->_handler)) {
            $this->_current = false;

            return;
        }

        $count = 0;
        $line = stream_get_line($this->_handler, self::DEFAULT_LENGTH, $this->_newline);
        if ($line === false) {
            $this->_current = false;

            return;
        }

        // Remove possible utf8-bom         if (str_starts_with($linepack('CCC', 0xEF, 0xBB, 0xBF))) {
            $line = substr($line, 3);
        }

        
Home | Imprint | This part of the site doesn't use cookies.