Q
替换字符串
3
A
回答
7
$finds = explode('-', "a - b - c");
if (count($finds) == 3) {
$finds[2] = " {$finds[2]}";
}
$finds = implode('-', $finds);
0
子串字符串从第一个破折号的索引处开始,使用strpos
,然后对该字符串的其余部分执行str_replace
。连接在一起。
1
$str ="a - b - c";
if (substr_count($str,"-")>2){
print preg_replace("/^(.*)-(.*)-(.*)/","\\1-\\2- \\3",$str);
}
+0
如果超过3 – Seaux 2010-03-11 00:32:47
+0
,则不起作用,然后为其添加检查。 – ghostdog74 2010-03-11 00:45:51
1
**// User Function to replace string by Occurance**
function str_occ_replace($from,$to,$subject,$occ){
$myArray = explode($from,$subject);
print_r($myArray);
$mystring = '';
$index = 1;
foreach($myArray as $ele){
if($index !== $occ AND $index !== $arraySize)
$mystring .= $ele.$from;
else if($index !== $arraySize)
$mystring .= $ele.$to;
$index++;
} // End of Foreach
return $mystring;
} // End of Function
+0
此代码完美起作用。 BOL。 – 2017-05-18 07:58:56
相关问题
- 1. 替换字符串
- 2. 替换字符串
- 3. 字符串替换
- 4. 替换字符串
- 5. 替换字符串[]
- 6. 替换字符串内的字符串
- 7. 字符串中的字符串替换
- 8. 将字符串替换为字符串
- 9. - 替换不替换字符串“()”
- 10. 字符串替换()/正则表达式替换 - 替换字符串数组中的字符串?
- 11. 字符串替换换行符
- 12. 用换行符替换字符串PHPStorm
- 13. PHP替换字符串
- 14. 替换从字符串
- 15. 替换文本字符串
- 16. 替换字符串“”没事
- 17. 字符串替换C#
- 18. 用XSLT替换字符串
- 19. grep和替换字符串
- 20. 批次字符串替换
- 21. PHP RegEx字符串替换
- 22. 字符串替换python
- 23. 替换字符串Python
- 24. 字符串forwardslash被替换
- 25. 字符串替换帮助
- 26. 用jquery替换字符串
- 27. 替换IP字符串
- 28. 替换字符串的JavaScript
- 29. JavaScript字符串替换
- 30. 替换字符串值
+1 - 发布了同样的答复(现已删除),但太晚:)。你想纠正你的最后一行。 like,$ result = implode(“ - ”,$ finds); – 2010-03-10 21:46:13
哈哈是啊,我已经不得不编辑BC了,我错过了第二次参照爆炸哈哈。 – Seaux 2010-03-11 00:31:52