這是一個例子:$original_string = 'I like apples very much. I want an apple.';$temp_string = str_replace('apples', '_apples_', $original_string);// $temp_string is now: I like _apples_ very much. I want an apple.$final_string = str_replace('apple', '_apple_', $temp_string);// $final_string is now: I like __apple_s_ very much. I want an _apple_.這不是我打算做的。我希望最終的字符串是:I like _apples_ very much. I want an _apple_.這就是我試圖做的:$original_string = 'I like apples very much. I want an apple.';$final_string = str_replace(['apples', 'apple'], ['_apples_', '_apple_'], $original_string);echo $original_string;// I like __apple_s_ very much. I want an _apple_. 顛倒更換順序也無濟(jì)于事:$original_string = 'I like apples very much. I want an apple.';$original_string = str_replace(['apple', 'apples'], ['_apple_', '_apples_'], $original_string);echo $original_string;// I like _apple_s very much. I want an _apple_. 我應(yīng)該怎么辦?
在 PHP 中第一次替換后停止替換字符串中的文本
呼喚遠(yuǎn)方
2023-06-24 17:35:18