views:

195

answers:

5
str_replace('Ê','',$line);

Ain't working. Is there some special string that represents that?

A: 

Try using preg_replace:

$line = preg_replace('/Ê/ui', '', $line);
shadowhand
+3  A: 

You need to consider the encoding of the string you want to manipulate. If that’s not encoded with the same character encoding as the file you declared that string above in is, you need to convert between both encodings.

The most common error is that either the data or the file is encoded in UTF-8 and the other in ISO 8859-1.

Gumbo
I had a hunch it was something like this, finally time for me to worry/learn about encodings.
rpflo
$line = str_replace('Ê','', mb_convert_encoding($line, "UTF-8"));
rpflo
+2  A: 

It's not clear if you know this, but str_replace doesn't work "in place", it returns a new string, so perhaps all you really needed was

$line=str_replace('Ê','',$line);

Another possibility is that you are looking at a Unicode combining diacritic, which is actually two unicode chars - the E and a circumflex diacritic.

Paul Dixon
This is what my code looks like, actually, I guess I should have left the $line out there on the other side.
rpflo
A: 

I think that's multibyte char, so try mb functions

usoban
A: 

I had to first convert the line to UTF-8.

mb_convert_encoding($line, "UTF-8")

So the code I ended up with is:

$line = str_replace('Ê','', mb_convert_encoding($line, "UTF-8"));

Answered my own question just to get the "solution" up instead of in a comment. Thanks Gumbo.

rpflo