Is there a PHP function that can do that?

I'm using strpos to get the position of a substring and I want to insert a string after that position.

推荐答案

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

http://php.net/substr_replace

In the above snippet, $pos is used in the offset argument of the function.

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

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

Php相关问答推荐

邮箱打开跟踪器不工作时发送邮件使用laravel调度程序

如何使用属性#[Embedded]嵌入带有规则的对象集合?

Laravel;Composer安装突然返回选项快捷方式不能为空.

WooCommerce:在 checkout 审核单和发票中显示定制产品数据

基于不用于变体的产品属性隐藏多个WooCommerce发货方式

创建一个Woocommerce我的帐户订单页面,仅显示已完成的订单

按列值将二维数组排序为不超过N个的递增组

如何使用定制的StateProvider设置JsonLd@上下文?

服务器升级到新的mysql版本8.0.34后查询错误

Google Drive API 服务->文件->get('root') 失败并显示找不到文件. (范围问题?)

Golang - Html 模板:如何创建导航项 - 子菜单?我找不到怎么做

我的功能以舒适的方式显示数组 struct

Windows 身份验证在 IIS 中验证什么?我可以在我的情况下禁用匿名身份验证吗?

如何通过帖子自定义元数据进行查询

如何在PHP中对多个脚本调用进行排队?

如何使用 WhatsApp Cloud API 向 WhatsApp 发送消息,而无需在发送消息之前注册收件人号码?

计算组合指数

为什么 AJAX 请求没有通过 is_ajax_request() codeigniter 的条件?

Docker: unixodbc.h 没有这样的文件或目录.已安装 unixodbc-dev 时出现pecl install sqlsrv错误

mysql / sql修复多对多数据库中的行