在PHP中的指定位置插入字符串
给定一个句子、一个字符串和位置,任务是将给定的字符串插入到指定位置。我们将从零开始计算头寸。请参阅下面的示例。
Input : sentence = ‘I am happy today.’
string = ‘very’
position = 4
Output :I amvery happy today.
Begin counting with 0. Start counting from the very first character till we reach
the given position in the given sentence.
Spaces will also be counted and then insert the given string at the specified position.
Input : sentence = ‘I am happy today.’
string = ‘ very’
position = 4
Output : I am very happy today.
这个想法是使用 substr_replace()
输出:
I am very happy today.