string str, pattern replace;
int max, first, last;
字符串 replace_string( str, pattern, replace );
字符串 replace_string( str, pattern, replace, max );
字符串 replace_string( str, pattern, replace, first, last );
字符串 str, pattern replace;
整数 max, first, last;
replace_string() 可以指定 replace 为空的字符串, 以用来除去字符串中特定的字. 举例来说: replace_string(" 1 2 3 ", " ", "") 会返回 "123". replace_string() 执行的速度比用 explode() 和 implode() 快.
第四和第五个参数可有可无 (这是为了相容于以前的版本). 这两个附加的参数有以下的功用:
第四个参数 first:
指定同一个字符串最多替换几次 (从 1 开始算). 如果这里指定为 0, 就当作是全部都换. 所以 replace_string("xyxx", "x", "z", 2) 会返回 "zyzx".
第五个参数 last:
第五个参数限制符合条件的范围:
first < 1: 从头开始全部替换.
last == 0 或 last > 最高符合数(max_matches): 全部替换到最后.
first > last: 完全不改变.