MDL-29027 fallback to mb_string on errors if available and simplify charset parsing