OpenCores
URL https://opencores.org/ocsvn/versatile_library/versatile_library/trunk

Subversion Repositories versatile_library

[/] [versatile_library/] [trunk/] [rtl/] [verilog/] [CSV.class.php] - Blame information for rev 124

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 40 unneback
<?php
2
 
3
class CSV {
4
 
5
    protected $file null;
6
    protected $header = array();
7
 
8
    function __construct($fileName) {
9
 
10
        $this->file fopen($fileName,'r');
11
 
12
        $this->parseHeader();
13
 
14
    }
15
 
16
    protected function getLine() {
17
 
18
        $line fgetcsv($this->file);
19
 
20
        if($this->isEmpty($line)) {
21
            return false;
22
        } else {
23
            return $line;
24
        }
25
 
26
    }
27
 
28
    function parseHeader() {
29
 
30
        do {
31
 
32
            $this->header $this->getLine();
33
 
34
        } while($this->header === false and !feof($this->file));
35
 
36
        return (count($this->header) > 0);
37
 
38
    }
39
 
40
    function getRow() {
41
 
42
        $array $this->getLine();
43
 
44
        if($array === false) {
45
 
46
            return false;
47
 
48
        } else {
49
 
50
            $return = array();
51
 
52
            foreach($array as $key => $val) {
53
                $return[$this->header[$key]] = $val;
54
            }
55
 
56
            return $return;
57
 
58
        }
59
 
60
    }
61
 
62
    function getRows() {
63
 
64
        $return = array();
65
 
66
        while($row $this->getRow()) {
67
            $return[] = $row;
68
        }
69
 
70
        return $return;
71
 
72
    }
73
 
74
    function isEmpty($row) {
75
        if($row === false or $row === array(null)) {
76
            return true;
77
        } else {
78
            foreach($row as $cur) {
79
                if(trim($cur) != '') {
80
                    return false;
81
                }
82
            }
83
            return true;
84
        }
85
    }
86
 
87
    function __destruct() {
88
        fclose($this->file);
89
    }
90
 
91
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.