NOTE. The g modifier is not required with the PHP PCRE implementation!
In addition to the Gumbo answer , use the g modifier to replace all punctuation events:
preg_replace('/[[:punct:]]/g', ' ', $string)
From Jonathan Lonowski (see comments):
> [The g modifier] means "Global" -- ie, find all existing matches. Without it, regex functions will stop searching after the first match.
strager Jan 24 '09 at 0:24 2009-01-24 00:24
source share