Suppose there\'s a string \"foo boo foo boo\" I want to replace all fooes with boo and booes with foo. Expected output is \"boo foo boo foo\". What I get is \"foo foo foo fo
First foo to zoo. Then boo to foo and last zoo to boo
foo
zoo
boo
$search = array('foo', 'boo', 'zoo'); $replace = array('zoo', 'foo', 'boo'); echo str_replace($search, $replace, $string);