$variable = 'one, two, three';
How can I replace the commas between words with <br>
?
$variable
should become:
one<br>
two<br>
three
Python String split() Method The split() method splits a string into a list. You can specify the separator, default separator is any whitespace. Note: When maxsplit is specified, the list will contain the specified number of elements plus one.
Windows 10 is a little different. To change the system delimiter default or as they call it "List Separator" to a comma you have to go to CONTROL PANEL / REGION / , Click on Additional Settings and then click on the drop down for List separator. You can select Comma from that list.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With