$variable = preg_replace('/\s*,\s*/', "<br>\n", $variable);
This will lead you to a land of regular expressions, but it will handle cases of random comma spacing, for example.
$variable = 'one,two, three';
or
$variable = 'one , two, three';
source
share