Ok if I use the code:
$phrase = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy = array("pizza", "beer", "ice cream");
$newphrase = str_replace($healthy, $yummy, $phrase);
// Provides: You should eat pizza, beer, and ice cream every day
However what if my list of words to replace are a variable.
$sample1 = "fruits, vegetables, fiber";
$sample2 = "pizza, beer, ice cream";
$phrase = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array($sample1);
$yummy = array($sample2);
$newphrase = str_replace($healthy, $yummy, $phrase);
// Provides: You should eat fruits, vegetables, and fiber every day.
Same if I use:
$sample1 = '"fruits", "vegetables", "fiber"';
$sample1 = '"pizza", "beer", "ice cream"';
$phrase = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array($sample1);
$yummy = array($sample2);
$newphrase = str_replace($healthy, $yummy, $phrase);
Am I missing something?
Is there a way to do this easily?