Is there an easy way to remove all non alphanumeric characters from a string in PHP that wouldn’t require listing them all individually in a regex function?
I have been using preg_replace("/[^a-zA-Z0-9\s\'\-]/", "", $my_string);in the past but this filters out important characters like ÀÈÌÒÙß etc.
I need to sanitize a name field, so monetary and mathematical characters/symbols are not needed.
Like this:
As arnaud576875 already mentioned, you should be aware that the pattern is treated as UTF-8 when using the
umodifier like I did. Relevant excerpt of the appropriate manual page: