php - How to import csv file to mysql in codeigniter -


i have format of csv file , can see there's "jan. 7, 2013" how can convert 2013-01-07.

ws-c3750x-48p-l,solaire,,fdo1651x2h9,"jan. 7, 2013","jan. 6, 2014",,1 year,cisco,covered under warranty,30 days,na,"jan. 2, 2013","apr. 2, 2014",1 year , 3 months,888-1,12643158 

adittional in format in csv file showing when use print_r() in top example not inserting can tell me why?

glc-sx-mm,solaire,,agm1620l2lu,no records,no records,,na,na,na,na,na,no records,no records,na,no records,no records 

here library code used.

code:

class csvreader {      var $fields;            /** columns names retrieved after parsing */      var $separator = ';';    /** separator used explode each line */     var $enclosure = '"';    /** enclosure used decorate each field */      var $max_row_size = 4096;    /** maximum row size used decoding */      function parse_file($p_filepath) {          $key_field = 'model,client_name,end_user,serial_num,trends_warranty_start,trends_warranty_end,client_contract_no,trends_warranty_period,vendor,support_coverage,sla,service_contract_num,support_coverage_start,support_coverage_end,support_coverage_period,trends_po,supplier_so';          $file = fopen($p_filepath, 'r');         $this->fields = fgetcsv($file, $this->max_row_size, $this->separator, $this->enclosure);         $keys_values  = explode(',',$key_field);          $content    =   array();         $keys   =   $this->escape_string($keys_values);          $i  =   0;         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 $row){             $result[]   =   str_replace('"', '',$row);         }         return $result;     }    } 

to convert "jan. 7, 2013" 2013-01-07.try one

$str = 'jan. 7, 2013'; echo date("y-m-d", strtotime($str)) 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -