views:

93

answers:

2

hey,

how can i parse a string to remove all non english characters in php

right now I want to remove things like

სოფო ნი�

Thanks :)

+3  A: 

By using preg_replace()

$string = "some სოფო text"; 
$string = preg_replace('/[^a-z0-9_ ]/i', '', $string); 

echo $string;

Granted, you will need to expand the preg_replace pattern, but that is one way to do it. There is probably a better way, I just do not know it.

Brad F Jacobs
+8  A: 
$str = preg_replace('/[^\00-\255]+/u', '', $str);
aularon
Very nicely done. Learned something new!
Brad F Jacobs
I'm happy that I can help and share the knowledge :)
aularon