How would I strip out all开发者_开发百科 characters from a string that does NOT contain: [a-zA-Z0-9\-\/_]
?
In other words, I'd like to specify what I DO want rather than what I don't. Thanks.
Easiest way:
preg_replace("/[^a-zA-Z0-9-\/_]/", '', $string);
Another approach would be to do a match and then implode the matched values.
try the following
preg_replace("/[^a-zA-Z0-9-\/_]/", "", $string);
If you want to keep a "/" and "\"
preg_replace("/[^a-zA-Z0-9-\\\/_]/", '', $string);
Shortest way to do it:
echo(preg_replace('~[^\w-/]~i', '', 'H#el/-l0:0.'));
Outputs:
"Hel/-l00"
精彩评论