...I can't resist... must... use... Regular Expressions
PHP Code:
$old_text = "ert, ert,ert,ert,ert";
$new_text = preg_replace('/,(?! )/', ', ', $old_text);
echo $new_text;
If you're curious, check out the
preg_replace function and the Pattern Syntax for
lookahead assertions.