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?

1

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

-1

Please use this one :

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

1 Comment

Please give some explanation around why that code is better and how it works to give more context to you answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.