Subversion Repositories computer_asset_manager_v1

Rev

Rev 41 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 41 Rev 45
Line 4... Line 4...
4
   {
4
   {
5
       private $fp;
5
       private $fp;
6
       private $parse_header;
6
       private $parse_header;
7
       private $header;
7
       private $header;
8
       private $delimiter;
8
       private $delimiter;
-
 
9
       private $enclosure;
-
 
10
       private $escape;
9
       private $length;
11
       private $length;
10
       private $analysis;
12
       private $analysis;
11
       public $lines;
13
       public $lines;
12
 
14
 
13
 
15
 
14
 
16
 
15
       //--------------------------------------------------------------------
17
       //--------------------------------------------------------------------
16
       function __construct($file_name, $parse_header=false, $delimiter='', $length=8000)
18
       function __construct($file_name, $parse_header=false, $delimiter='', $enclosure='"', $escape = '', $length=8000 )
17
       {
19
       {
18
           // auto detect mac file endings
20
           // auto detect mac file endings
19
           ini_set('auto_detect_line_endings',TRUE);
21
           ini_set('auto_detect_line_endings',TRUE);
20
 
22
 
21
           $this->parse_header = $parse_header;
23
           $this->parse_header = $parse_header;
22
           $this->delimiter = $delimiter;
24
           $this->delimiter = $delimiter;
23
           if ( $delimiter === '' ) { # do an auto-detect on the file
25
           if ( $delimiter === '' or $delimiter == 'auto' ) { # do an auto-detect on the file
24
              $this->analysis = $this->analyse_file( $file_name );
26
              $this->analysis = $this->analyse_file( $file_name );
25
              $this->delimiter = $this->analysis['delimiter']['value'];
27
              $this->delimiter = $this->analysis['delimiter']['value'];
-
 
28
            } elseif ( $delimiter == 'tab' ) {
-
 
29
               $this->delimiter = "\t";
26
            } else {
30
            } else {
27
               $this->delimiter = $delimiter;
31
               $this->delimiter = $delimiter;
28
            }
32
            }
-
 
33
            $enclosure = $enclosure == 'auto' ? '' : $enclosure;
-
 
34
            $this->enclosure = $enclosure ? $enclosure : '"';
-
 
35
            
-
 
36
            $this->escape = $escape ? $escape : '\\';
29
            $this->length = $length;
37
            $this->length = $length;
30
            $this->lines = 0;
38
            $this->lines = 0;
31
 
39
 
32
           $this->fp = fopen($file_name, "r");
40
           $this->fp = fopen($file_name, "r");
33
 
41
 
34
           if ($this->parse_header)
42
           if ($this->parse_header)
35
           {
43
           {
36
              $this->header = fgetcsv($this->fp, $this->length, $this->delimiter);
44
              $this->header = fgetcsv($this->fp, $this->length, $this->delimiter, $this->enclosure, $this->escape );
37
           }
45
           }
38
 
46
 
39
       }
47
       }
40
       //--------------------------------------------------------------------
48
       //--------------------------------------------------------------------
41
       function __destruct()
49
       function __destruct()
Line 55... Line 63...
55
           if ($max_lines > 0)
63
           if ($max_lines > 0)
56
               $line_count = 0;
64
               $line_count = 0;
57
           else
65
           else
58
               $line_count = -1; // so loop limit is ignored
66
               $line_count = -1; // so loop limit is ignored
59
 
67
 
60
           while ($line_count < $max_lines && ($row = fgetcsv($this->fp, $this->length, $this->delimiter)) !== FALSE)
68
           while ($line_count < $max_lines && ($row = fgetcsv($this->fp, $this->length, $this->delimiter, $this->enclosure, $this->escape )) !== FALSE)
61
           {
69
           {
62
               if ($this->parse_header)
70
               if ($this->parse_header)
63
               {
71
               {
64
                   foreach ($this->header as $i => $heading_i)
72
                   foreach ($this->header as $i => $heading_i)
65
                   {
73
                   {