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: 完全不改變.