Page 1 of 1

How to remove none-characters and digits from a string?

Posted: Fri Oct 19, 2007 8:34 pm
by jasongr
Hi people

I have a string that could contain any character (from any language).
I would like to remove all non-characters and digits from it.
I could use:

Code: Select all

$new_string = ereg_replace("[^A-Za-z0-9]", "", $string);
however this will only work for strings with English characters.
I am looking for a solution that will also work for example in German, Chinese and so on.

Does anyone know of such a solution?

regards

Posted: Sat Oct 20, 2007 3:36 am
by Kieran Huggins
the \w set may include non-roman characters, but I'd double check to be sure

Posted: Sat Oct 20, 2007 5:55 am
by jasongr
I found out that mb_ereg_replace and blacklisting unwanted letters is the way to go