I’m having trouble using str_replace when it comes across two words that contain similar characters.
For instance, is the words “music” and “musical instruments” are in the array, str_replace will only replace the the second variable up to the point the first variable stopped.
When str_replace sees “music” in “musical instruments”, it changes it to the undesired value
// This should say - You should play stupid, dumber, and wig-out every day.
$phrase = “You should play music, musical instruments, and practice every day.”;
$phrase1 = array(’/music/’,’/musical_instruments/’,’/practice/’);
$phrase2 = array(‘stupid’,‘dumber’,‘wig-out’);
$newphrase = preg_replace($phrase1, $phrase2, $phrase);
// Instead it returns - You should play stupid, stupidal instruments, and wig-out every day.
Is there a way to make it recognize the difference between the two different words?
Thanks in advance for any help!