Replacing words in strings
Listed In Uncategorized » — Viewing Full Tutorialstr_replace(what you're looking for, what you wanna replace it with, where you're looking);
So, as an example:
$msg = "Dan is alright.";
$bettermsg = str_replace("alright", "god", $msg);
echo $bettermsg;
This would print: Dan is god.
You can also use it with arrays. Say we had a string full of pointless numbers, this snippet would clean it out for us.
$msg = "1He3l64lo 4w5o865rl1d2.";
$numbers = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "0");
$cleanmsg = str_replace($numbers, "", $msg);
echo $cleanmsg;
This would print: Hello world.
Hope this is of help to people in their scripts and applications. :)
