php遍历CSV类实例

yipeiwu_com5年前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点击可刷新验证码的具体代码,供大家参考,具体内容如下 验证码类文件 CreateImg.class.php <?php class Va...

php IP转换整形(ip2long)的详解

如何将四个字段以点分开的IP网络址协议地址转换成整数呢?PHP里有这么一个函数ip2long.比如复制代码 代码如下:<?phpecho ip2long("10.2.1.3");?...

PHP删除指定目录中的所有目录及文件的方法

本文实例讲述了PHP删除指定目录中的所有目录及文件的方法。分享给大家供大家参考。具体实现方法如下: <?php /* * * 删除指定目录中的所有目录及文件(或者...

zend api扩展的php对象的autoload工具

类似spl的autoload功能,bloader为php对象的autoload工具,但相比较起来更简单高效,配置也更灵活. bloader提供一个常用的autoload函数ld,以及两个...

DEDE采集大师官方留后门的删除办法

去除官方后门方法:安装好采集大师后,请立即删除 include目录下的dedesql.query.php文件,如已经安装过,有可能文件已被改名为arc.sqlquery.class.ph...