I want to remove commas when importing data from an excel file to the database and i use phpexcel library for importing the data
i have a controller like this for importing the excel file
M_excel.php
public function import(){
$user = $this->ion_auth->user()->row();
include APPPATH.'third_party/PHPExcel/PHPExcel.php';
$excelreader = new PHPExcel_Reader_Excel2007();
$loadexcel = $excelreader->load('excel/'.$this->filename.'.xlsx');
$sheet = $loadexcel->getActiveSheet()->toArray(null, true, true ,true);
$data = array();
$numrow = 4;
foreach($sheet as $row){
if($numrow > 4){
array_push($data, array(
'NO' => $row['A'],
'APIID' => $row['B'],
'Jan19' => $row['C'],
'Feb19' => $row['D'],
'Mar19' => $row['E'],
'Apr19' => $row['F'],
'May19' => $row['G'],
'Jun19' => $row['H'],
'Jul19' => $row['I'],
'Aug19' => $row['J'],
'Sep19' => $row['K'],
'Oct19' => $row['L'],
));
}
$numrow++;
}
$this->m_excel->insert_multiple($data);
redirect("excel_import");
}
just replace the comma by using str_replace(",", "", "string here") like below
$data = array();
$i=0;
foreach($sheet as $row){
if($numrow > 4){
$data[$i]['NO'] = $row['A'];
$data[$i]['APIID'] = $row['B'];
$data[$i]['Jan19'] = str_replace(",", "", $row['C']) // use str_replace where you want to replace comma
$data[$i]['Feb19'] = $row['D'];
$data[$i]['Mar19'] = $row['E'];
$data[$i]['Apr19'] = $row['F'];
$data[$i]['May19'] = $row['G'];
$data[$i]['Jun19'] = $row['H'];
$data[$i]['Jul19'] = $row['I'];
$data[$i]['Aug19'] = $row['J'];
$data[$i]['Sep19'] = $row['K'];
$data[$i]['Oct19'] = $row['L'];
}
$i++;
$numrow++;
}
$this->m_excel->insert_multiple($data);
redirect("excel_import");