I periodically wrap myself around the error unserialize(): Error at offset when unserializing data from a database. I use base64_encode \ base64_decode to smooth operations, and it worked before then, but if that fails. I found findSerializeError here, but can't figure out what it does. If I knew what he was doing, I would be able to fix serialization errors myself. I would appreciate it if someone explained to me what this function does. Here is the function code:
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; } } }
php
AngularInDepth.com Oct 20 '13 at 12:04 on 2013-10-20 12:04
source share