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登录环节防止sql注入的方法浅析

在防止sql注入这些细节出现问题的一般是那些大意的程序员或者是新手程序员,他们由于没有对用户提交过来的数据进行一些必要的过滤,从而导致了给大家测试的时候一下就攻破了你的数据库,下面我们来...

php常用图片处理类

本文为大家分享的php常用图片处理类,供大家参考学习,具体内容如下 <?php /*已知问题:1.在图片缩放功能中,使用imagecreatetruecolor函数创建...

PHP中函数gzuncompress无法使用的解决方法

前言 gzuncompress函数不是php自带的系统函数而是一个插件函数了所以要使用 gzuncompress函数我们必须安装一个插件,下面来看看PHP函数gzuncompress无法...

解决微信授权回调页面域名只能设置一个的问题

解决微信授权回调页面域名只能设置一个的问题

最终的解决方案是:https://github.com/liuyunzhuge/php_weixin_proxy,详细的介绍请往下阅读。 在做项目集成微信登录以及微信支付的时候,都需要进...

PHP简单实现定时监控nginx日志文件功能示例

本文实例讲述了PHP简单实现定时监控nginx日志文件功能。分享给大家供大家参考,具体如下: 此功能是为了实现,定时监控nginx生成的日志数据,并将新增的数据提交到一个接口(比如大数据...