1

I am importing CSV file data, The first Line is columns name for me, What i found in first column name is,

<font color='#cc0000'>'LEG_NO'</font> <i>(length=9)</i>
 0 => string 'LEG_NO' (length=9)

The LEG_NO Column contains only 6 characters but when I dump in PHP it shows 9 characters, So I searched for this string online here, i got FEFF ZERO WIDTH NO-BREAK SPACE

Can anybody help me to remove this special character from variable? Which will help me to compare the fields

Chintan7027
  • 7,115
  • 8
  • 36
  • 50
  • No, trim is not removing this special character – Chintan7027 Feb 22 '17 at 08:42
  • This is almost certainly the result of reading in a file with a Unicode [byte-ordering mark](https://en.wikipedia.org/wiki/Byte_order_mark). In your example this is the three byte BOM that specifies the file is encoded as [UTF-8](https://en.wikipedia.org/wiki/UTF-8) (0xEF 0xBB 0xBF). – Phylogenesis Feb 22 '17 at 08:43

1 Answers1

2

I had a similar issue with a sql file generated by mssql-scripter and which I was trying to import with doctrine using vendor/bin/doctrine dbal:import file.sql.

Found the answer here

$sql = preg_replace("/\xEF\xBB\xBF/", "", $sql);

or use sed on the csv file in your case

sed -i "s/\xEF\xBB\xBF//g" file.csv
Shadi
  • 9,742
  • 4
  • 43
  • 65