-1
A
回答
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");
2
爲什麼你的解決方案不起作用:
substr_replace("hello",",",2);
取代與,
。這意味着它將從索引2
中取代substring
。這就是爲什麼你的解決方案無法工作。
有什麼解決辦法:
`substr_replace("hello",",",2,0);` instead.
2
試試這個:
echo str_replace("he", "he,", "hello");
http://php.net/manual/en/function.substr-replace.php
str_replace函數: 字符串的一部分中替換文本
相關問題
- 1. 找到次數字符串「hello hello」的次數的正則表達式出現在字符串「hello hello hello」中
- 2. 如何將值「」hello「」賦值給一個字符串?
- 3. Excel VBA。如何將字符串「Hello World」轉換爲數字向量
- 4. 如何將數據從IO(字符串)
- 5. 如何使用Saxon-HE中的XSLT fn:document函數讀取XML字符串?
- 6. 將「Hello World」字符串反轉爲「World Hello」,出現了什麼問題?
- 7. 如何在黃瓜中打印「Hello World」字符串?
- 8. 如何在EFI Shell腳本中傳遞字符串「Hello#」
- 9. 將字符串從字符串複製到字符串
- 10. 如何將字符串
- 11. 如何將字符串
- 12. 如何將字符串
- 13. 如何將字符串
- 14. 如何將字符串的字符串轉換爲字符?
- 15. 如何從字符串中刪除動態字符字符串?
- 16. 我如何從字符串
- 17. 如何從字符串
- 18. 如何從字符串
- 19. 如何從字符串
- 20. 如何從字符串
- 21. 如何從JSON字符串
- 22. 如何從字符串
- 23. 如何從字符串
- 24. 如何從字符串
- 25. 如何使從字符串
- 26. 如何從字符串
- 27. 如何從字符串
- 28. 如何從字符串
- 29. 如何從字符串
- 30. 如何從字符串android
背後的邏輯是什麼? – DonCallisto
多麼神祕。 – Kyslik