Substr_replace
(PHP4 >= 4.0b4)
Substr_replace---&http://www.aliyun.com/zixun/aggregation/37954.html ">nbsp; A part of a string that replaces a string
Syntax: String substr_replace (String string, string replacement, int start [, int length])
Description:
Substr_replace () Replaces string partial strings, specifying the bounds by the parameter start and length, and substituting the parameter replacement.
If the argument start is a positive number, the substituted string begins with the first character of the string.
If the argument start is a positive number, the substituted string starts at the start character at the end of the string.
If there is a given parameter length and is a positive number, it represents the length of the part string to be replaced by the string. If length is negative, it represents the number of characters to be aborted from the end of a string. If this argument is not given, it is preset to the length of the parameter string.
Example:
<?php
$var = ' abcdefgh:/mnrpqr/';
echo "Original: $var <hr>\n";
/* This nonblank examples replace all $var with ' Bob '. */
Echo substr_replace ($var, ' Bob ', 0). "<br>\n";
Echo substr_replace ($var, ' Bob ', 0, strlen ($var)). "<br>\n";
/* Insert ' Bob ' right at the beginning of $var. */
Echo substr_replace ($var, ' Bob ', 0, 0). "<br>\n";
/* These next nonblank replace ' MNRPQR ' in $var with ' Bob '. */
Echo substr_replace ($var, ' Bob ', 10,-1). "<br>\n";
Echo substr_replace ($var, ' Bob ',-7,-1). "<br>\n";
/* Delete ' MNRPQR ' from $var. *
Echo substr_replace ($var, ', 10,-1). "<br>\n";
?>
Note: This function is the new function in PHP 4.0
Reference: Str_replace () substr ()