Substitute Using str_replace

12Feb08

Sometimes you simply want to replace part of string with something else, like changing your address when you move. You could use a fancy grep replace or similar functionality, but if it is a simple substitution it is usually easier to just go with the string function str_replace.

Here is how it works:
$newwork = str_replace($old, $new, $work)

Just set $old to the string of characters you want replaced, $new to the new value you want there (it can be an empty string if you just want to remove something without replacing it), and $work is your original string text. The modified version will be stored in $newwork.