How would I remove all characters from a string that does NOT contain [a-zA-Z0-9\-\/_] :?
[a-zA-Z0-9\-\/_]
In other words, I would like to indicate what I want, not what I don't have. Thanks.
The easiest way:
preg_replace("/[^a-zA-Z0-9-\/_]/", '', $string);
Another approach would be to do the match and then explode the matched values.
try the following
preg_replace("/[^a-zA-Z0-9-\/_]/", "", $string);
If you want to keep "/" and "\"
preg_replace("/[^a-zA-Z0-9-\\\/_]/", '', $string);
The shortest way to do it:
echo(preg_replace('~[^\w-/]~i', '', 'H#el/-l0:0.'));
Outputs:
"Hel/-l00"