Sometimes, we want to insert a string at a specified position with PHP.
In this article, we’ll look at how to insert a string at a specified position with PHP.
How to insert a string at a specified position with PHP?
To insert a string at a specified position with PHP, we can use the substr_replace
function.
For instance, we write
$newstr = substr_replace($oldstr, $str_to_insert, $pos, 0);
to call substr_replace
with $oldStr
to insert $str_to_insert
starting at index $pos
.
Conclusion
To insert a string at a specified position with PHP, we can use the substr_replace
function.