国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php遍歷CSV類實例

2024-05-04 23:34:10
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了php遍歷CSV類,實例分析了php針對csv文件的打開、讀取及遍歷的技巧,非常具有實用價值,需要的朋友可以參考下

本文實例講述了php遍歷CSV類。分享給大家供大家參考。具體如下:

 

 
  1. <?php 
  2. class CSVIterator implements Iterator 
  3. {  
  4. const ROW_SIZE = 4096; 
  5. private $filePointer
  6. private $currentElement
  7. private $rowCounter
  8. private $delimiter
  9. public function __construct( $file$delimiter = ',' ) 
  10. $this->filePointer = fopen$file'r' ); 
  11. $this->delimiter = $delimiter
  12. public function rewind() 
  13. $this->rowCounter = 0; 
  14. rewind$this->filePointer ); 
  15. public function current() 
  16. $this->currentElement = fgetcsv($this->filePointer,self::ROW_SIZE,$this->delimiter); 
  17. $this->rowCounter++; 
  18. return $this->currentElement; 
  19. public function key() 
  20. return $this->rowCounter; 
  21. public function next() 
  22. return !feof$this->filePointer ); 
  23. public function valid() 
  24. if( !$this->next() ) 
  25. fclose( $this->filePointer ); 
  26. return FALSE; 
  27. return TRUE; 
  28. // end class 
  29. ?> 

希望本文所述對大家的php程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汉沽区| 宁阳县| 肥东县| 新乡县| 大宁县| 社旗县| 洪洞县| 双柏县| 宜宾市| 临湘市| 天祝| 高雄市| 高密市| 天峨县| 安岳县| 清流县| 宝清县| 梨树县| 报价| 西吉县| 遂溪县| 新沂市| 东源县| 普定县| 枞阳县| 海晏县| 阿巴嘎旗| 南乐县| 舞阳县| 海丰县| 宁都县| 四会市| 如东县| 瑞丽市| 旬阳县| 固始县| 遂平县| 湖南省| 安阳县| 肇东市| 无为县|