• 技术文章 >后端开发 >php教程

    php遍历CSV类实例_php技巧

    2016-05-16 20:17:44原创658
    本文实例讲述了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入门到就业线上直播课:查看学习

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

    前端(VUE)零基础到就业课程:点击学习

    清晰的学习路线+老师随时辅导答疑

    快捷开发Web应用及小程序:点击使用

    支持亿级表,高并发,自动生成可视化后台。

    专题推荐:php 遍历 CSV
    上一篇:php生成rss类用法实例_php技巧 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • ❤️‍🔥共22门课程,总价3725元,会员免费学• ❤️‍🔥接口自动化测试不想写代码?• 浅析PHP8.0特性:Named Parameter(命名参数)• 手把手教你用PHP快速连接SqlServer• zend api扩展的php对象的autoload工具_PHP教程• php cookis创建实现代码_PHP教程• 继续收藏一些PHP常用函数第1/2页_PHP教程
    1/1

    PHP中文网