gpt4 book ai didi

php - 在指定位置插入字符串

转载 作者:IT老高 更新时间:2023-10-28 11:38:47 25 4
gpt4 key购买 nike

有没有 PHP 函数可以做到这一点?

我正在使用 strpos 来获取子字符串的位置,我想在该位置之后插入一个 string

最佳答案

$newstr = substr_replace($oldstr, $str_to_insert, $pos, 0);

http://php.net/substr_replace

在上面的代码片段中,$pos 用于函数的 offset 参数中。

offset
If offset is non-negative, the replacing will begin at theoffset'th offset into string.

If offset is negative, the replacing will begin at the offset'thcharacter from the end of string.

关于php - 在指定位置插入字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8251426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com