I would recommend str_replace for such a simple operation. It has simplier functionality, bit it is much faster than preg_replace: $text = str_replace(' ', '+', $text); PHP:
I'm well aware of that (and I was almost sire someone would pick up on that), but I decided to use preg_replace() to replace multiple spaces with just one plus sign.
nico, I understand your point, it's OK, it depends on what he needs. I've just provided another solution for his task. About multiple spaces: it seems he needs to encode urls (' ' => '+', '&' => '%26' etc.) so the best solution for that should be $text = urlencode($text); PHP: