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程序设计有所帮助。

相关文章

利用phpexcel对数据库数据的导入excel(excel筛选)、导出excel

话不多说,请看代码: <?php date_default_timezone_set("PRC"); error_reporting(E_ALL); error_re...

修改php.ini以达到屏蔽错误信息并记录日志

那是因为php.ini中关闭了错误显示,将错误写成了文件,这是人为设置的结果,display_errors =on就好了。 不过不显示错误倒安全点,建议调试时打开,然后提供服务时关闭。...

windows下安装php的memcache模块的方法

windows下安装php的memcache模块的方法

要求必备知识 熟悉基本编程环境搭建。 运行环境 windows 7(64位); php-5.3; memcached-1.2.6 下载地址 环境下载 什么是PHP Memcache模块...

PHP生成可点击刷新的验证码简单示例

本文实例讲述了PHP生成可点击刷新的验证码。分享给大家供大家参考,具体如下: html文件: <html> <head> <title>验...

php实现的三个常用加密解密功能函数示例

php实现的三个常用加密解密功能函数示例

本文实例讲述了php实现的三个常用加密解密功能函数。分享给大家供大家参考,具体如下: 算法一: //加密函数 function lock_url($txt,$key='www.jb5...