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

相关文章

PHPMailer的主要功能特点和简单使用说明

支持邮件 s/mime加密的数字签名 支持邮件多个 TOs, CCs, BCCs and REPLY-TOs 可以工作在任何服务器平台,所以不用担心WIN平台无法发送邮件的问题的 支持文...

php+ajax登录跳转登录实现思路

当我们的用户进行系统登录时,用户名和密码的验证都是后端验证的。而且,用户登录状态也是要后端设置的,查询数据库后,用户名和密码正确,则在session中存储一个uuid,每个页面需要根据登...

PHP实现的QQ空间g_tk加密算法

本文实例讲述了PHP实现的QQ空间g_tk加密算法。分享给大家供大家参考。具体如下: //G_tk计算 function getGTK($skey){ $hash = 5381;...

PHP中常见的密码处理方式和建议总结

PHP中常见的密码处理方式和建议总结

前言 在使用PHP开发Web应用的中,很多的应用都会要求用户注册,而注册的时候就需要我们对用户的信息进行处理了,最常见的莫过于就是邮箱和密码了,本文意在讨论对密码的处理:也就是对密码的加...

PHPThumb PHP 图片缩略图库

1、这是一个缩略图类库 它是一个开源的图片缩略图类库,可以完成多种复杂的图片缩略图生成和现实,使用起来非常的方便。 2、使用方法 这里有一篇关于其简单实用的说明,英文比较简单,就不翻译了...