I'm trimming the first_name and the last_name of my users on a Model via Eloquent Accessors with the next helper:
function clean($string){
return trim($string, " \t\n\r\0\x0B\xc2\xa0");
}
Then in the model:
public function getFirstNameAttribute($firstname){
return clean(ucwords(strtolower($firstname)));
}
public function getLastNameAttribute($lastname){
return clean(ucwords(strtolower($lastname)));
}
A lot of names comes from an excel an has trailing spaces which can be removed trimming \xa0, but the problem comes when it tries to trim special characters, as (à).
I tried removing it and it doesn't fail, but well, it doesn't remove the trailing spaces.
I also tried making sure that the headers charset were set to utf-8
Any idea? Thanks.
I just want the invisible spaces to be gone :/
The error message:
InvalidArgumentException in JsonResponse.php line 69:
Malformed UTF-8 characters, possibly incorrectly encoded