本文实例讲述了php遍历csv类。分享给大家供大家参考。具体如下:
<?php class csviterator implements iterator { const row_size = 4096; private $filepointer; private $currentelement; private $rowcounter; private $delimiter; public function __construct( $file, $delimiter = ',' ) { $this->filepointer = fopen( $file, 'r' ); $this->delimiter = $delimiter; } public function rewind() { $this->rowcounter = 0; rewind( $this->filepointer ); } public function current() { $this->currentelement = fgetcsv($this->filepointer,self::row_size,$this->delimiter); $this->rowcounter++; return $this->currentelement; } public function key() { return $this->rowcounter; } public function next() { return !feof( $this->filepointer ); } public function valid() { if( !$this->next() ) { fclose( $this->filepointer ); return false; } return true; } } // end class ?>
希望本文所述对大家的php程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
[ACTF2020 新生赛]Include 1【文件包含】【读取代码】
算法题解 - 牛客编程巅峰赛S1第6场 - 黄金&钻石&王者组
推荐一个程序员必备网站之一:Dev Hints ,非常实用!
网友评论