如何更改列表的分隔符?
问题描述:
答
要么使用str_replace
:
$variable = str_replace(", ", "<br>", $variable);
,或者,如果你想要做其他事情与元素之间,explode()
和implode()
:
$variable_exploded = explode(", ", $variable);
$variable_imploded = implode("<br>", $variable_exploded);
答
$variable = str_replace(", ","<br>\n",$variable);
应该这样做。
答
$variable = explode(', ',$variable);
$variable = implode("<br/>\n",$variable);
然后,您可以只echo $variable
答
你可以这样做:
$variable = str_replace(', ',"<br>\n",$variable);
答
$variable = preg_replace('/\s*,\s*/', "<br>\n", $variable);
这需要你进入正则表达式的土地,但这样会处理逗号之间的随机间距,例如病例
$variable = 'one,two, three';
或
$variable = 'one , two, three';
这是非常昂贵的.. – Petrogad 2010-09-17 13:44:12