錯誤「unserialize() [function.unserialize]: Error at offset」可能是由下列原因造成的由於位元組計數長度不正確,序列化字串無效。
要解決此問題,我們需要重新計算序列化數組中元素的長度。這是使用提供的資料的範例:
$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";}'; $data = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('').':\"\";'", $data);
重新計算長度後,我們現在可以反序列化資料而不會出現錯誤:
var_dump(unserialize($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():偏移處錯誤”?的詳細內容。更多資訊請關注PHP中文網其他相關文章!