正则表达式/代码来修复损坏的序列化PHP数据. [英] Regex/ code to fix corrupt serialized PHP data.

查看:124
本文介绍了正则表达式/代码来修复损坏的序列化PHP数据.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个庞大的多维数组,已被PHP序列化.它已存储在MySQL中,并且数据字段不够大...末端已被切断...我需要提取数据... unserialize无法正常工作...有谁知道代码可以关闭所有数组...重新计算字符串长度...手工处理的数据太多.

I have a massive multidimensional array that has been serialised by PHP. It has been stored in MySQL and the data field wasn't large enough... the end has been cut off... I need to extract the data... unserialize wont work... does anyone know of a code that can close all the arrays... recalculate string lengths... it's too much data to do by hand.

非常感谢.

推荐答案

我认为这几乎是不可能的. 在修理阵列之前,您需要知道阵列是如何损坏的. 有多少孩子失踪?内容是什么?

I think this is almost impossible. Before you can repair your array you need to know how it is damaged. How many childs missing? What was the content?

对不起,恕我直言.

证明:

<?php

$serialized = serialize(
    [
        'one'   => 1,
        'two'   => 'nice',
        'three' => 'will be damaged'
    ]
);

var_dump($serialized); // a:3:{s:3:"one";i:1;s:3:"two";s:4:"nice";s:5:"three";s:15:"will be damaged";}

var_dump(unserialize('a:3:{s:3:"one";i:1;s:3:"two";s:4:"nice";s:5:"tee";s:15:"will be damaged";}')); // please note 'tee'

var_dump(unserialize('a:3:{s:3:"one";i:1;s:3:"two";s:4:"nice";s:5:"three";s:')); // serialized string is truncated

链接: https://ideone.com/uvISQu

即使您可以重新计算键/值的长度,也不能信任从此源检索到的数据,因为您不能重新计算键/值的值.例如.如果序列化的数据是对象,那么您的属性将不再可用.

Even if you can recalculate length of your keys/values, you cannot trust the data retrieved from this source, because you cannot recalculate the value of these. Eg. if the serialized data is an object, your properties won't be accessible anymore.

这篇关于正则表达式/代码来修复损坏的序列化PHP数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆