【发布时间】:2017-10-24 05:08:52
【问题描述】:
我的字符串是这样的
$str="12345"
我想得到
$str1 = "1,2,3,4,5"
【问题讨论】:
-
@Nidhi OP希望在文本中用逗号分隔,而不是转换为数组。
-
但不要再用这个了:
implode(",",(str_split('123456')))
我的字符串是这样的
$str="12345"
我想得到
$str1 = "1,2,3,4,5"
【问题讨论】:
implode(",",(str_split('123456')))
没有爆炸或内爆:
$str="123456789";
echo substr(chunk_split($str,1,","),0,-1);
【讨论】:
$strLen = strlen($s);
$o = '';
for($i =0; $i < $strLen; $i++) {
$comma = ($i < $strLen) ? ' , ' : '';
$o .= $strLen[$i] . $comma;
}
echo $o;
【讨论】:
使用str_split 和implode 展开数组
implode(str_split('testing'), ',')
会给你
t,e,s,t,i,n,g
对于 1234 也是如此
【讨论】:
if看源码,你赢了比较:github.com/php/php-src/blob/…
试试这个,检查 live demo
implode(',', str_split($str));
【讨论】: