我只想替换以下字符串:
This is my first sentence.
.:.
This is my second sentence.
.:.
This is my third sentence.
.:.
输出应该是:
This is my first sentence.
1
This is my second sentence.
2
This is my third sentence.
3
我怎样才能更有效,更轻松地完成这项工作?
答案 0 :(得分:2)
echo preg_replace_callback("/@/",
function(){static $count=0; return ++$count;},
"A@B@C@");