how could I remove all characters from a string that aren’t a-z/A-Z and 0-9 and _ with PHP?
I tried that but it has no effect, it returns the same string back:
preg_replace('[^a-zA-Z0-9_]', '', 'Testdo123_-:=)§%&');
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
preg_prefixed functions require PCRE styled regular expression that use delimiters to separate the regular expression from optional flags/modifiers.But you forgot delimiters. Or, to be precise: PHP takes the
[and]as delimiters, leaving just^a-zA-Z0-9_as your actual regular expression.So try this (using
/as delimiters):