修復位元組計數長度不正確的損壞的序列化字串
發生錯誤「unserialize() [function.unserialize]:偏移處錯誤」當反序列化因位元組計數長度不正確而損壞的資料。若要解決此問題,請重新計算序列化陣列中元素的長度。
序列化不正確:
$data = 'a:10:{s:16:"submit_editorial";b:0;s:15:"submit_orig_url";s:13:"www.bbc.co.uk";s:12:"submit_title";s:14:"No title found";s:14:"submit_content";s:12:"dnfsdkfjdfdf";s:15:"submit_category";i:2;s:11:"submit_tags";s:3:"bbc";s:9:"submit_id";b:0;s:16:"submit_subscribe";i:0;s:15:"submit_comments";s:4:"open";s:5:"image";s:19:"C:fakepath100.jpg";}';
輸出:
Notice: unserialize() [function.unserialize]: Error at offset 337 of 338 bytes
重新計算序列化:
$data = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('').':\"\";'", $data);
輸出:
array 'submit_editorial' => boolean false 'submit_orig_url' => string 'www.bbc.co.uk' (length=13) 'submit_title' => string 'No title found' (length=14) 'submit_content' => string 'dnfsdkfjdfdf' (length=12) 'submit_category' => int 2 'submit_tags' => string 'bbc' (length=3) 'submit_id' => boolean false 'submit_subscribe' => int 0 'submit_comments' => string 'open' (length=4) 'image' => string 'C:fakepath100.jpg' (length=17)
其他注意事項:
以上是如何修復由序列化字串中的位元組計數長度不正確導致的'unserialize(): Error at offset”?的詳細內容。更多資訊請關注PHP中文網其他相關文章!