独立字符串逗号

问题描述:

我有串独立字符串逗号

$string=" Tag tag1 tag2"; 

我要输出字符串逗号的形式:

OUTPUT:

标签,标签1,标签2

+5

爆炸,内爆,完成。 – CBroe

+0

^只是想说;打败了我。 –

+0

使用[str_replace](http://php.net/manual/en/function.str-replace.php)如果它们始终由相同的字符分隔。 – KhorneHoly

$string=" Tag tag1 tag2"; 

print implode(',',explode(' ',trim($string))); 
//or 
print str_replace(' ',',',trim($string)); 
//or 
print preg_replace('#()#',',',trim($string)); 

http://php.net/manual/en/ref.strings.php