php遍历CSV类实例
本文实例讲述了php遍历CSV类。分享给大家供大家参考。具体如下:
<?php
classCSVIteratorimplementsIterator
{
constROW_SIZE=4096;
private$filePointer;
private$currentElement;
private$rowCounter;
private$delimiter;
publicfunction__construct($file,$delimiter=',')
{
$this->filePointer=fopen($file,'r');
$this->delimiter=$delimiter;
}
publicfunctionrewind()
{
$this->rowCounter=0;
rewind($this->filePointer);
}
publicfunctioncurrent()
{
$this->currentElement=fgetcsv($this->filePointer,self::ROW_SIZE,$this->delimiter);
$this->rowCounter++;
return$this->currentElement;
}
publicfunctionkey()
{
return$this->rowCounter;
}
publicfunctionnext()
{
return!feof($this->filePointer);
}
publicfunctionvalid()
{
if(!$this->next())
{
fclose($this->filePointer);
returnFALSE;
}
returnTRUE;
}
}//endclass
?>
希望本文所述对大家的php程序设计有所帮助。
热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短