Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the delimiter of a list?

Tags:

php

explode

$variable = 'one, two, three';

How can I replace the commas between words with <br>?

$variable should become:

one<br>
two<br>
three
like image 555
James Avatar asked Sep 17 '10 13:09

James


People also ask

How do I change the separator in a list Python?

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.

How do I change the delimiter in Windows 10?

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.


1 Answers

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);
like image 69
Pekka Avatar answered Sep 20 '22 11:09

Pekka