这是一个例子:
$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_.
颠倒更换顺序也无济于事:
$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_.
我应该怎么办?
慕森卡