php遍历CSV类实例

yipeiwu_com6年前PHP代码库

本文实例讲述了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程序设计有所帮助。

相关文章

php实现多维数组排序的方法示例

本文实例讲述了php实现多维数组排序的方法。分享给大家供大家参考,具体如下: //定义一个学生数组 $students = array( 256=>array('name'...

解析PHP 5.5 新特性

PHP5.5 前不久前刚刚发布,里面的新特性有什么?官方文档在这里:http://www.php.net/manual/zh/migration55.new-features.php1...

php实现比较全的数据库操作类

本文实例讲述了php实现比较全的数据库操作类。分享给大家供大家参考。具体如下: <?php class database { private $hostname...

php表单提交实例讲解

php表单提交实例讲解

本文为大家分享了一个特别简单的php表单提交实例,具体的实现步骤如下: 实例代码如下: <form action="someform.php" method="post">...

php使用ftp实现文件上传与下载功能

本文实例为大家分享了php ftp文件上传与下载的具体代码,供大家参考,具体内容如下 ftp文件上传 php自带有ftp操作的函数包,一个比较简单实现的ftp文件上传操作可以通过以下几个...