Girish
Girish

Reputation: 12127

php import csv special char issue

I am trying to import CSV in php by 'fgetcsv()' function, but the CSV file has some hidden characters, these character as not showing in Excel or notepad, i can see only one char in browser console.

enter image description here

i have tried to remove these characters by trim(), utf8_decode() as well preg_replace() but no solution has coming up.

trim($value, ' \t\n\r\0\x0B\x00..\x1F\x09\0x0A');
preg_replace($value, '/[\x00-\x1F\x7F]/u', '', $value);

And finally, I am facing issue in following CSV file, please provide a solution, how i can rid red dot(.) char in import.

Upvotes: 1

Views: 1472

Answers (1)

Nigel Ren
Nigel Ren

Reputation: 57121

Looks as though this has a Byte Order Marker for UTF8 (from https://en.wikipedia.org/wiki/Byte_order_mark) at the start of the file. You can remove it by using...

if ( substr($value,0,3) === chr(239).chr(187).chr(191))    {
    $value = substr($value, 3);
}

or

$value = trim($value, chr(239).chr(187).chr(191));

Upvotes: 2

Related Questions