Problem with PHP encoding and character with symbol Γ‚

I had a problem when PHP (5.2) cannot find the β€œΓ‚β€ character in the string, although it is clearly there.

I understand that the main problem is with character encoding, but unfortunately I can’t control the original content. I get it as UTF-8, with these characters already in the string.

I just wanted to remove it from the string. strpos (), str_replace (), preg_replace (), trim (), etc. It is not possible to identify it correctly.

My line is this:

"Γ‚ Γ‚ Γ‚ A lot of couples throughout the World " 

If I do this:

 $string = str_replace('Γ‚','',$string); 

I get this:

 "Γ‚  Γ‚  Γ‚  A lot of couples throughout the World" 

I even tried utf8_encode () and utf8_decode () before str_replace, no luck.

What's the solution? I drop everything I can find in it ...

+4
source share
3 answers

I use this:

 function replaceSpecial($str){ $chunked = str_split($str,1); $str = ""; foreach($chunked as $chunk){ $num = ord($chunk); // Remove non-ascii & non html characters if ($num >= 32 && $num <= 123){ $str.=$chunk; } } return $str; } 
+3
source
 $string = str_replace('Γ‚','',$string); 

How is this encoded? If your script file is saved as iso-8859-1, the string 'Γ‚' is encoded as one byte sequence xC2, and the representation (/ one) utf-8 is encoded as xC3 x82. php str_replace () works at the byte level, that is, it only "knows" single-byte characters.

see http://docs.php.net/intro.mbstring

+4
source
+1
source