I have a dg call that i want to do str_replace to several parts of the text. How do i do str_repalce several times to the same text. like if I grabbed a story from the database and I wanted to replace every boston with miami and every Stan with Bob and every fly with drive how would i do that? I can do one with : echo str_replace("boston", "miami", "$text"); PHP: but how do you do it multiple times
$text1 = str_replace('boston', 'miami', $text); $text2 = str_replace('Stan', 'Bob', $text1); $text3 = str_replace('fly", 'drive', $text2); echo $text3;
This is a bad practice. Now you have 3 variables which hold (almost) exactly the same as the one you need. Plus you have 2 more function calls. It's unnecessary slow, and takes more resources. Note that in PHP, you can overwrite variables anytime you want.