使用ascii代码32 - 47删除所有字符,并从字符串中删除更多字符

I want to remove all characters with ascii codes 32 - 47 and some more from string. Exactly !"#$%&'()*+,-./\~.

I tried:

$string = preg_replace('/\s\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\\~/', '', $string);

But it returned false. What am I doing wrong? Thanks.

To use the characters just include them in a character class:

$string = preg_replace(':[\s!"#$%&\'()*+,-./\\\~]:', '', $string);

Or use ASCII hexadecimal for the range and characters:

[\x20-\x2f\x5c\x7e]

Or use the actual characters in a range as long as you start with the first (space) and end with the last / in the range and then add the rest:

[ -/\\\~]