Replaces part of a string.
This function replaces a portion of a string with another string, starting at the specified position. A negative start position gives an offset from the end of the string. By default, the rest of the string after the starting position is replaced with the replacement string. If a length is specified, that will be the number of characters replaced. If length is negative it specifies a number of characters counted from the end of the string that should be spared from replacement.
<?php
print substr_replace("0123456789", "111", 1) . "<br>";
print substr_replace("0123456789", "555", -4) . "<br>";
print substr_replace("0123456789", "111", 1, 2) . "<br>";
print substr_replace("0123456789", "777", -3, -1) . "<br>";
?>
0111
012345555
01113456789
01234567779
This code demonstrates the effects of different arguments to substr_replace().