Make str_replace DRY and more flexible (thanks  onefriendaday)