Michael Jackson Michael Jackson - 17 days ago 6
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

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