I know this should remove any characters from string and keep only numbers and ENGLISH letters.
$txtafter = preg_replace("/[^a-zA-Z 0-9]+/","",$txtbefore);
but I wish to remove any special characters and keep any letter of any language like Arabic or Japanese.
Probably this will work for you:
This will remove all non-word and non-space characters from your text.
/u
flag is there for unicode support.You can use the
\p{L}
pattern to match any letter and\p{N}
to much any numeric character. Also you should useu
modifier like this:/\p{L}+/u
Your final regex may look like:
/[^\p{L}\p{N}]/u
Also be sure to check this question:
Regular expression \p{L} and \p{N}