Server IP : 164.52.202.56 / Your IP : 216.73.216.208 Web Server : Apache System : Linux e2e-70-56.ssdcloudindia.net 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Tue Nov 5 04:50:16 EST 2024 x86_64 User : rubyaromatics ( 1052) PHP Version : 7.2.34 Directory (0755) : /home/rubyaromatics/public_html/crm/application/libraries/ |
[ Home ] | [ Terminal ] | [ Upload File ] |
---|
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class CSVReader { var $fields; /** columns names retrieved after parsing */ var $separator = ';'; /** separator used to explode each line */ var $enclosure = '"'; /** enclosure used to decorate each field */ var $max_row_size = 4096; /** maximum row size to be used for decoding */ function parse_file($p_Filepath) { $file = fopen($p_Filepath, 'r'); $this->fields = fgetcsv($file, $this->max_row_size, $this->separator, $this->enclosure); $keys_values = explode(',',$this->fields[0]); $content = array(); $keys = $this->escape_string($keys_values); $i = 1; while(($row = fgetcsv($file, $this->max_row_size, $this->separator, $this->enclosure)) != false ) { if( $row != null ) { // skip empty lines $values = explode(',',$row[0]); if(count($keys) == count($values)){ $arr = array(); $new_values = array(); $new_values = $this->escape_string($values); for($j=0;$j<count($keys);$j++){ if($keys[$j] != ""){ $arr[$keys[$j]] = $new_values[$j]; } } $content[$i] = $arr; $i++; } } } fclose($file); return $content; } function escape_string($data) { $result = array(); foreach($data as $row){ $result[] = str_replace('"', '',$row); } return $result; } } ?>