PHP substr_replace Replacement string Specify position character
/*
int Mb_strlen (String $str [, String $encoding])
<?php Tutorial
Echo substr_replace ("Hello World", "Earth", 6); Hello Earth
?>
It is worth mentioning that when the start and length are both negative and the length is less than or equal to the beginning, the length will have an effect set to 0.
<?php
substr_replace (' Eggs ', ' x ', -1,-1); Eggxs
substr_replace (' Eggs ', ' x ', -1,-2); Eggxs
substr_replace (' Eggs ', ' x ', -1,-2); Eggxs
?>
Mahouve as:
<?php
Substr_replace (' eggs ', ' x ', -1,0); Eggxs
?>
<?php
substr_replace (' Huevos ', ' x ', -2,-2); Huevxos
substr_replace (' Huevos ', ' x ', -2,-3); Huevxos
substr_replace (' Huevos ', ' x ', -2,-3); Huevxos
?>
Mahouve as:
<?php
substr_replace (' Huevos ', ' x ', -2,0); Huevxos
?>
Another note that if the length is negative and the starting offset is the same length position, the length (again) will have an effect that is set to 0. (Of course, mentioned in the manual, when the length is negative it actually represents the previous position)
<?php
Substr_replace (' ABCD ', ' X ', 0,-4); Xabcd
?>
Mahouve as:
<?php
Substr_replace (' ABCD ', ' X ', 0,0); Xabcd
?>
<?php
Substr_replace (' ABCD ', ' X ', 1,-3); Axbcd
?>
Mahouve as:
<?php
Substr_replace (' ABCD ', ' X ', 1, 0); Axbcd
?>
Look at the parameter description
String required. Specify the string to check.
Replacement required. Specify the string to insert.
Start Required. Specify where the string begins to be replaced.
Positive number-replace at start offset
Negative number-replaces the start offset at the end of the string
0-Start the substitution at the first character in the string
Charlist Optional. Specify how many characters to replace.
Positive number-The length of the string being replaced
Negative numbers-the number of replaced characters starting at the end of the string
0-Insert rather than replace