Please could anyone enlighten me on how I would archive the following!!
I want to replace a space with an underscore except when the space is after a comma. So something like this
tag 1, tag 2, tag 3
becomes
tag_1, tag_2, tag_3
You could consider regex, e.g.,
$text = 'tag 1, tag 2, tag 3'; echo preg_replace('/(?<!,) /', '_', $text);
Thanks very much laserlight! 😃
Or, without lookbehind
$text = 'tag 1, tag 2, tag 3'; echo preg_replace('/([^,]) /', '$1_', $text);
(Unlike Laserlight's pattern, this would not replace a space at the beginning of the string, not sure if that is crucial to you.)