2010-09-17 200 views

回答

12

要麼使用str_replace

$variable = str_replace(", ", "<br>", $variable); 

,或者,如果你想要做其他事情與元素之間,explode()implode()

$variable_exploded = explode(", ", $variable); 
$variable_imploded = implode("<br>", $variable_exploded); 
8
$variable = str_replace(", ","<br>\n",$variable); 

應該這樣做。

5
$variable = explode(', ',$variable); 
$variable = implode("<br/>\n",$variable); 

然後,您可以只echo $variable

+0

這是非常昂貴的.. – Petrogad 2010-09-17 13:44:12

3

你可以這樣做:

$variable = str_replace(', ',"<br>\n",$variable); 
3
$variable = preg_replace('/\s*,\s*/', "<br>\n", $variable); 

這需要你進入正則表達式的土地,但這樣會處理逗號之間的隨機間距,例如病例

$variable = 'one,two, three'; 

$variable = 'one , two, three'; 
相關問題