Michael Jackson Michael Jackson - 8 months ago 50
PHP Question

Remove all special characters but keep dots and accents

I'm trying to remove all special characters from a string keeping dots and accents. I already got the accents working, how can I allow the dots?

My function.

function clean($string) {

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

}


Thanks

Answer Source

Add a dot to your character group. /[^\p{LN}\-.]/u <-- see the dot