2

I want to strip a string from all characters, except for: Alphanumeric characters, spaces and accented letters.

I got it to work for everything except for the accented letters:

$fname = preg_replace("/[^\w\space/", "", $fname);

What do I need to change in order to allow accented letters in the output?

Davey D
  • 432
  • 3
  • 20

3 Answers3

3

When I was struggling to get things working, I found the answer myself, so I decided to share it with you:

$fname = preg_replace("/[^\w\space\pL]/", "", $fname);

The "pL" part matches anything in the Unicode letter category, so accented letters are allowed in the output.

Davey D
  • 432
  • 3
  • 20
0

i found solution.

Accented letter

$str = 'paulraâj píc - accountant and knows Bilingüe';

Removing Accented letter

echo '<br>' .preg_replace('/[^a-zA-Z0-9_ -]/s', '', $str);

Result : paulraj pc - accountant and knows Bilinge
wow works great
Thanks

Dharman
  • 30,962
  • 25
  • 85
  • 135
Solomon Suraj
  • 1,162
  • 8
  • 8
-1

Please use this one :

$fname = preg_replace("/[^ \w]+/", "", $fname);
Kuldeep Raj
  • 791
  • 1
  • 7
  • 29
  • 2
    Please give some explanation around why that code is better and how it works to give more context to you answer – stuyam Dec 28 '15 at 21:29