Remove whitespace from csv

0

I have a problem when the user uploads a .CSV file. If some of the fields have a blank space at the end I can not remove it in any way.

For example: "[email protected]"

I have tried to use trim() , rtrim() and it does not work When I use str_replace() it removes all the spaces that it has in the middle of the string but that of the end does not remove.

I have looked everywhere and I do not find a solution. If anyone can help me, thank you.

Code as requested:

foreach($column_headers as $key => $value)
{
     $result[$new_row][$value] = trim($data[$key]);
}
    
asked by anonymous 02.08.2017 / 22:05

1 answer

1

The only way I was able to remove this blank space was like this:

$email = preg_replace('/[[:^print:]]/', '', $email);

From what I saw, this '/[[:^print:]]/' removes unprintable characters.

    
04.08.2017 / 14:40