Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel whitespaces not removed from individual cells

Tags:

php

phpexcel

I have an Excel file with values as follows.

 avi|boom|
ben |boom|

I upload the file and use phpExcel to read and get values from each cell. The whitespaces before avi and after ben how do I remove them in php. I tried using the trim function but data is stored in database with whitespaces.

trim($sheet->getCell('B'.$row )->getValue());

data still gets stored with whitespaces.

like image 275
AAB Avatar asked Feb 13 '23 11:02

AAB


1 Answers

The additional whitespace is a non-breaking whitespace character (xA0), not a standard value included in php trim(). You can remove it using the following trim modification.

trim(iconv("UTF-8","ISO-8859-1",$sheet->getCell('B'.$row )->getValue())," \t\n\r\0\x0B\xA0");
like image 103
XaxD Avatar answered Feb 15 '23 00:02

XaxD