PHP Traversal CSV class instance
Specific as follows:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21st
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 |
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
?>
|
http://www.bkjia.com/PHPjc/983320.html www.bkjia.com true http://www.bkjia.com/PHPjc/983320.html techarticle The PHP traversal of the CSV class instance is as follows: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 7. PHP-Class Csviterator ...