-1

I just started writing PHP again after a few years on other languages and I read through some of my older scripts, and found this regular expression that I can't seem to remember writing, and I can't seem to find an answer for what it does.

The context is cleaning up some user input. Does it have anything to do with UTF8 or Latin character ranges?

$keyword = preg_replace('/[^ -~]/iu', '\\S{0,1}', $keyword);

1 Answers1

1

Yes. The regular expression is replacing characters which are NOT between space and tilde ... characters before space are control characters and characters after tilde are not 7bit ASCII. (Space is character number 32 and tilde 126.)

Honza
  • 401
  • 2
  • 9