3

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.

Cœur
  • 34,719
  • 24
  • 185
  • 251
medo ampir
  • 1,732
  • 7
  • 30
  • 56

2 Answers2

7

Probably this will work for you:

$repl = preg_replace('/[^\w\s]+/u','' ,$txtbefore);

This will remove all non-word and non-space characters from your text. /u flag is there for unicode support.

anubhava
  • 713,503
  • 59
  • 514
  • 593
2

You can use the \p{L} pattern to match any letter and \p{N} to much any numeric character. Also you should use u 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}

Community
  • 1
  • 1
Adam Zielinski
  • 2,644
  • 1
  • 22
  • 33