2

I would like to change all special characters in my string but I want to keep all accented ones. Is it possible with a preg_replace() ?

My current code:

preg_replace('/[^A-Za-z0-9\-]/', '', $string); 
HamZa
  • 14,051
  • 11
  • 52
  • 72
Dimitri
  • 912
  • 2
  • 13
  • 33

1 Answers1

5

Try Unicode:

preg_replace('/[^\p{L}0-9\-]/u', '', $string);

\p{L} is a Unicode property that matches all letters in any language, Unicode properties on php.net

stema
  • 85,585
  • 19
  • 101
  • 125