c6ifsw
Last Updated: February 25, 2016
·
6.673K
· dfeddad
3eb40bd16fb620ff4ac2c1712c6edd08

Simple way to insert a string into another string at any position in PHP

If you want a very simple and short solution to insert string into another string use:
substr_replace ( $string , $replacement , $start , 0 ). The key here is zero, and because we set $length to zero this function will have the effect of inserting the replacement into the string.

<?php

$string = 'I am happy today.';
$replacement = 'very ';

echo substr_replace($string, $replacement, 4, 0); // I am very happy today.
Say Thanks
Respond