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:
[ -/\\\~]