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全局使用Laravel辅助函数dd

dump() 方法 全局 composer.json "require": { "squizlabs/php_codesniffer": "*", "fxp/composer...

php数据库密码的找回的步骤

1.用系统管理员登陆系统。 2.停止MySQL的服务。 3.进入命令窗口,然后进入MySQL的安装目录,比如我的安装目录是c:mysql,进入C:mysqlbin 4.跳过权限检查启动M...

php弹出对话框实现重定向代码

1 利用js 实现 复制代码 代码如下: if(!$this->userInfo){ $alert_msg = "激活链接错误"; echo"<SCRIPT LANGUAGE...

php安全之直接用$获取值而不$_GET 字符转义

复制代码 代码如下: <? function my_addslashes($string, $force = 0) { !defined('MAGIC_QUOTES_GPC') &...

PHP计算当前坐标3公里内4个角落的最大最小经纬度实例

本文实例讲述了PHP计算当前坐标3公里内4个角落的最大最小经纬度的方法。分享给大家供大家参考,具体如下: //$lng 、$lat 经纬度 $half = 6371;...