1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- /**
- * dolphin. Collection of useful PHP skeletons.
- * Copyright (C) 2013 Johannes 'Banana' Keßler
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
- *
- * You should have received a copy of the
- * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
- * along with this program. If not, see http://www.sun.com/cddl/cddl.html
- */
- /**
- * how to "repair" an serilized string to get the data back.
- * it can not solve everything but it might help to recover some otherwise lost data
- */
- /**
- * the error message "Error at offset"
- * this inticates a malformed string. with the following method you can
- * find out where and what could be the error
- * At first use the exact offset from the error message and choose a length of 3
- * then you can get backwards and choose a longer range to identify the error
- * if you have utf-8 data, make sure you set the right encoding header.
- */
- var_export(substr($serializedStr, OFFSET, LENGTH););
- /**
- * there is a better way to store and save the data to avoid malformed data
- */
- $toDatabse = base64_encode(serialize($data)); // Save to database
- $fromDatabase = unserialize(base64_decode($data)); //Getting Save Format
- /**
- * finding the error in the serilized string.
- * based on a idea from stackoverflow
- *
- * @param string The serilized string
- */
- function findSerializeError($data1) {
- echo "<pre>";
- $data2 = preg_replace ( '!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'",$data1 );
- $max = (strlen ( $data1 ) > strlen ( $data2 )) ? strlen ( $data1 ) : strlen ( $data2 );
- echo $data1 . PHP_EOL;
- echo $data2 . PHP_EOL;
- for($i = 0; $i < $max; $i ++) {
- if (@$data1 {$i} !== @$data2 {$i}) {
- echo "Diffrence ", @$data1 {$i}, " != ", @$data2 {$i}, PHP_EOL;
- echo "\t-> ORD number ", ord ( @$data1 {$i} ), " != ", ord ( @$data2 {$i} ), PHP_EOL;
- echo "\t-> Line Number = $i" . PHP_EOL;
- $start = ($i - 20);
- $start = ($start < 0) ? 0 : $start;
- $length = 40;
- $point = $max - $i;
- if ($point < 20) {
- $rlength = 1;
- $rpoint = - $point;
- } else {
- $rpoint = $length - 20;
- $rlength = 1;
- }
- echo "\t-> Section Data1 = ", substr_replace ( substr ( $data1, $start, $length ), "<b style=\"color:green\">{$data1 {$i}}</b>", $rpoint, $rlength ), PHP_EOL;
- echo "\t-> Section Data2 = ", substr_replace ( substr ( $data2, $start, $length ), "<b style=\"color:red\">{$data2 {$i}}</b>", $rpoint, $rlength ), PHP_EOL;
- }
- }
- }
- ?>
|