这篇文章主要为大家详细介绍了php 遍历CSV的类用法示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编罗X来看看吧。
<?php
/**
* 遍历CSV类
*
* @param
* @arrange (512.笔记) www.q1010.com
**/
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
?>
本文来自:http://www.q1010.com/173/501-0.html
注:关于php 遍历CSV的类用法示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:CSV
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。