php遍历CSV类实例


Posted in PHP onApril 14, 2015

本文实例讲述了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 OPCode缓存 APC详细介绍
Oct 12 PHP
洪恩在线成语词典小偷程序php版
Apr 20 PHP
php读取文件内容至字符串中,同时去除换行、空行、行首行尾空格(Zjmainstay原创)
Jul 31 PHP
浅析php学习的路线图
Jul 10 PHP
CodeIgniter错误mysql_connect(): No such file or directory解决方法
Sep 06 PHP
php实现无限级分类
Dec 24 PHP
PHP实现通过Luhn算法校验信用卡卡号是否有效
Mar 23 PHP
php获取网页里所有图片并存入数组的方法
Apr 06 PHP
Zend Framework实现Zend_View集成Smarty模板系统的方法
Mar 05 PHP
实例讲解php数据访问
May 09 PHP
PHP编写简单的App接口
Aug 28 PHP
详解PHP用mb_string处理windows中文字符
May 26 PHP
php获取twitter最新消息的方法
Apr 14 #PHP
php检测url是否存在的方法
Apr 14 #PHP
PHP中把对象转换为关联数组代码分享
Apr 09 #PHP
Laravel 5 框架入门(四)完结篇
Apr 09 #PHP
PHP四种基本排序算法示例
Apr 09 #PHP
Laravel 5 框架入门(三)
Apr 09 #PHP
Laravel 5 框架入门(二)构建 Pages 的管理功能
Apr 09 #PHP
You might like
PHP无限分类代码,支持数组格式化、直接输出菜单两种方式
2011/05/18 PHP
php时间戳格式化显示友好的时间函数分享
2014/10/21 PHP
php生成mysql的数据字典
2016/07/07 PHP
php排序算法实例分析
2016/10/17 PHP
Yii框架学习笔记之session与cookie简单操作示例
2019/04/30 PHP
JavaScript中“+”的陷阱深刻理解
2012/12/04 Javascript
jQuery获取注册信息并提示实现代码
2013/04/21 Javascript
jQuery前端分页示例分享
2015/02/10 Javascript
JavaScript动态修改背景颜色的方法
2015/04/16 Javascript
各式各样的导航条效果css3结合jquery代码实现
2016/09/17 Javascript
AngularJS常见过滤器用法实例总结
2017/07/06 Javascript
微信禁止下拉查看URL的处理方法
2017/09/28 Javascript
JS实现的Object数组去重功能示例【数组成员为Object对象】
2019/02/01 Javascript
layer.msg()去掉默认时间,实现手动关闭的方法
2019/09/12 Javascript
Vue数字输入框组件使用方法详解
2020/02/10 Javascript
[05:41]2014DOTA2西雅图国际邀请赛 小组赛7月10日TOPPLAY
2014/07/10 DOTA
20个常用Python运维库和模块
2018/02/12 Python
python批量导入数据进Elasticsearch的实例
2018/05/30 Python
python实现本地图片转存并重命名的示例代码
2018/10/27 Python
python实现合并两个排序的链表
2019/03/03 Python
PyQt5固定窗口大小的方法
2019/06/18 Python
关于python中plt.hist参数的使用详解
2019/11/28 Python
Python3.7基于hashlib和Crypto实现加签验签功能(实例代码)
2019/12/04 Python
python构造IP报文实例
2020/05/05 Python
Python 没有main函数的原因
2020/07/10 Python
分享30个新鲜的CSS3打造的精美绚丽效果(附演示下载)
2012/12/28 HTML / CSS
印尼最大的在线购物网站:MatahariMall.com
2016/08/26 全球购物
美国购买新书和二手书网站:Better World Books
2018/10/31 全球购物
Feelunique中文官网:欧洲最大化妆品零售电商
2020/07/10 全球购物
《去年的树》教学反思
2014/04/11 职场文书
2014世界杯球队球队口号
2014/06/05 职场文书
代理人委托书
2014/08/01 职场文书
2015年世界无车日活动总结
2015/03/23 职场文书
裁员通知
2015/04/25 职场文书
Windows10下安装MySQL8
2021/04/06 MySQL
SQL Server2019安装的详细步骤实战记录(亲测可用)
2022/06/10 SQL Server