Using the POSIX character classes
How to match [:cntrl:] but excluding the [:space:]?
$message = ereg_replace("[[:cntrl:]]", "", $message);
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.
ereg_* (POSIX) functions have been deprecated for a long time now. You should not contiue using these methods.
According to POSIX Bracket Expressions
[:cntrl:]resolves to the ASCII range[\x00-\x1F\x7F](or the unicode\p{Cc}) and[:space:]resolves to[ \t\r\n\v\f]. Using asciitable.com to resolve those characters, you are left with an exclusion list of[\x20\x09-\x0D]. “Doing the math” you are left with[\x00-\x08\x0E-\x1F\x7F]. and that leaves you with the following, PHP 5.3 and upward compatible, sanitization:Note that
VT(Vertical Tab) andFF(Form Feed, New page) are also preserved. Depending on your situation you might want to remove these, too: