有时我们的API接收到无效的UTF8内容,系统需要一种安全的方法来序列化无效的UTF8字符串,以便可以将其存储在数据库中。出于可见性目的,需要这样做。
$response = new Response(200,[],str_split('??')[0]);
try {
$responseContent = unserialize($response->getBody()->getcontents());
} catch (\Exception $e) {
die($e);
}
以上内容将引发“通知:unserialize():偏移量为1字节的0错误”错误消息。
是否可以像这样安全地序列化一个损坏的字符串,以便可以将其存储在数据库中?
谢谢