Check if charset attribute exists before calling force_encode