Reputation: 994
I'm trying to upload a CSV file, read its contents and import that data into a database, but apparently I'm getting some kind of bug where an unknown character shows between each character.
This is my code:
$file = $request->file('file');
$fileName = $file->getRealPath();
$file = fopen($fileName, "r");
$i = 0;
while (($column = fgetcsv($file, 10000, ";")) !== FALSE) {
if ($i == 0){
$i++;
continue;
}
echo print_r($column);$i++;
}
fclose($file);
This is what I get from print_r:
Any ideas on what could it be? I've tried opening the CSV with encoding UTF8 and UTF16 but I still have this issue.
Thanks in advance.
Upvotes: 1
Views: 373
Reputation: 43507
Most likely it's \0
char that some system appends. Check with ord($string[0])
You can simply do str_replace("\0", '', $string)
Or try some regex replace: preg_replace('/[^\w\d-.,\s]/', '', $string)
Upvotes: 1