Published in: PHP
I think I got this one off php.net. I wish I could thank the author properly because this has been a real helper!
<?php class CSVIterator implements Iterator { const ROW_SIZE = 4096; private $filePointer; private $currentElement; private $rowCounter; private $delimiter; public function __construct( $file, $delimiter = ',' ) { $this->delimiter = $delimiter; } { $this->rowCounter = 0; } { $this->rowCounter++; return $this->currentElement; } { return $this->rowCounter; } { } public function valid() { if( !$this->next() ) { return FALSE; } return TRUE; } } // end class ?>
Comments
Subscribe to comments
You need to login to post a comment.

That's the best code snippet I've seen in a long time. I can't even begin to describe how useful this is. :)