How to repair a serialized string which has been corrupted by an incorrect byte count length?

后端 未结 15 2008
后悔当初
后悔当初 2020-11-22 11:46

I am using Hotaru CMS with the Image Upload plugin, I get this error if I try to attach an image to a post, otherwise there is no error:

unserialize()

15条回答
  •  [愿得一人]
    2020-11-22 12:44

    public function unserializeKeySkills($string) {
        $output = array();
        $string = trim(preg_replace('/\s\s+/', ' ',$string));
        $string = preg_replace_callback('!s:(\d+):"(.*?)";!', function($m) { return 's:'.strlen($m[2]).':"'.$m[2].'";'; }, utf8_encode( trim(preg_replace('/\s\s+/', ' ',$string)) ));
        try {
            $output =  unserialize($string);
        } catch (\Exception $e) {
            \Log::error("unserialize Data : " .print_r($string,true));
        }
        return $output;
    }
    

提交回复
热议问题