$variable = 'one, two, three';
How can I replace the commas between words with <br>
?
$variable
should become:
one<br>
two<br>
three
$variable = 'one, two, three';
How can I replace the commas between words with <br>
?
$variable
should become:
one<br>
two<br>
three
Either use str_replace
:
$variable = str_replace(", ", "<br>", $variable);
or, if you want to do other things with the elements in between, explode()
and implode()
:
$variable_exploded = explode(", ", $variable);
$variable_imploded = implode("<br>", $variable_exploded);
$variable = str_replace(", ","<br>\n",$variable);
Should do the trick.
$variable = explode(', ',$variable);
$variable = implode("<br/>\n",$variable);
You can then just echo $variable
$variable = preg_replace('/\s*,\s*/', "<br>\n", $variable);
This takes you into regex land but this will handle cases of random spacing between commas, e.g.
$variable = 'one,two, three';
or
$variable = 'one , two, three';