I need to replace the word 'me' with the word 'you', and the word 'you' with the 'me' simultaneously. It works with strtr() when the 2 words aren't next to each other, but when they are, it replaces the first word, then ignores the second word. Is there any way to fix this?
<?php
$string = "tell me you want to get it right";
$string = trim(strtr(" ".trim($string)." ", array(
" me " => " you ",
" you " => " me "
)));
echo $string;
?>
Actual Result:
tell you you want to get it right
Need Result:
tell you me want to get it right
PS: Don't really want any answers that uses something like "Replace all 'you's with 'you1234', and then all 'me's with 'me1234', then just replace all 'you1234's with 'me', and all 'me1234's with 'you'.