Make substitutions for most invalid characters rather than stripping them.