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
  • 37,241
  • 25
  • 195
  • 267
medo ampir
  • 1,850
  • 7
  • 33
  • 57

2 Answers2

8

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
  • 761,203
  • 64
  • 569
  • 643
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,774
  • 1
  • 25
  • 36