substr_replaceReplace text within a portion of a string
&reftitle.description;
mixedsubstr_replacemixedstringstringreplacementintstartintlengthsubstr_replace replaces a copy of
string delimited by the
start and (optionally)
length parameters with the string given in
replacement.
&reftitle.parameters;
string
The input string.
replacement
The replacement string.
start
If start is positive, the replacing will
begin at the start'th offset into
string.
If start is negative, the replacing will
begin at the start'th character from the
end of string.
length
If given and is positive, it represents the length of the portion of
string which is to be replaced. If it is
negative, it represents the number of characters from the end of
string at which to stop replacing. If it
is not given, then it will default to strlen(
string ); i.e. end the replacing at the
end of string. Of course, if
length is zero then this function will have the
effect of inserting replacement into
string at the given
start offset.
&reftitle.returnvalues;
The result string is returned. If string is an
array then array is returned.
&reftitle.examples;
substr_replace example
\n";
/* These two examples replace all of $var with 'bob'. */
echo substr_replace($var, 'bob', 0) . " \n";
echo substr_replace($var, 'bob', 0, strlen($var)) . " \n";
/* Insert 'bob' right at the beginning of $var. */
echo substr_replace($var, 'bob', 0, 0) . " \n";
/* These next two replace 'MNRPQR' in $var with 'bob'. */
echo substr_replace($var, 'bob', 10, -1) . " \n";
echo substr_replace($var, 'bob', -7, -1) . " \n";
/* Delete 'MNRPQR' from $var. */
echo substr_replace($var, '', 10, -1) . " \n";
?>
]]>
&reftitle.notes;
¬e.bin-safe;
&reftitle.seealso;
str_replacesubstrString access and modification by character