2013-06-06 47 views

回答

1

如何:

$str = "Hello" ; 
echo substr($str,0,2) . "," . substr($str,2) ; 
2

下面是答案

substr_replace("hello",",",2,0); 
+0

+1您的簡單答案有效。不知道你爲什麼沒有得到upvotes。 –

4

您應該使用str_replace就像我的例子。

例子:

str_replace("hello","he,llo","hello"); 
+3

我很樂意爲幽默的緣故upvote這個答案:D –

+0

我受到了Martin Solveig的啓發.. –

+0

非常好的回答:) – Sangar82

2

爲什麼你的解決方案不起作用:

substr_replace("hello",",",2);取代​​與,。這意味着它將從索引2中取代substring。這就是爲什麼你的解決方案無法工作。

有什麼解決辦法:

 `substr_replace("hello",",",2,0);` instead.