Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove all occurrences of c2a0 in a string with PHP?

Tags:

php

csv

utf-8

I'm working with a CSV file which is exported from Excel.

I have a column that contains a value of 1 234,00. I need to get all whitespaces away from these kinds of columns with PHP and I've tried to do it with preg_replace("/\s*/","",$column) as well as with str_replace(" ","",$column). I was almost ready to lose it so I took a glance into the csv-file with a HEX-editor and noticed, that this space consist of two hex values, C2 and A0 which seems to be UTF-8 non-breaking space.

But I suck with encoding stuff and I'm still confused in finding a way to remove them. Any ideas?

like image 627
BudwiseЯ Avatar asked Oct 27 '11 23:10

BudwiseЯ


2 Answers

$column = str_replace("\xc2\xa0", '', $column);
like image 58
phihag Avatar answered Sep 22 '22 11:09

phihag


You may use trim

trim($data['value'], " \t\n\r\0\x0B\xc2\xa0")

Where \t\n\r\0\x0B is defualt mask, \xc2\xa0 need add

like image 34
Andrey Vorobyev Avatar answered Sep 20 '22 11:09

Andrey Vorobyev