Esempio n. 1
0
    public function fetch()
    {
        if (!isset($this->fp)) {
            $this->fp = fopen($this->filename, "r");
        }
        if (!feof($this->fp)) {
            return $line = fgets($this->fp, 4096);
        } else {
            fclose($this->fp);
            $this->fp = NULL;
            return false;
        }
    }
}
$file = new FileIterator("colors-iterator.php");
while (($line = $file->fetch()) !== false) {
    //echo$line."<br/>";
}
class FileIterator2 implements Iterator
{
    private $filename;
    private $fp = NULL;
    public function __construct($file)
    {
        $this->filename = $file;
    }
    public function __destruct()
    {
        fclose($this->fp);
    }
    public function rewind()