VarjuOrg

Linux / Windows – what’s the difference…

unserialize() : Error at offset XX:XXX

Food for thought:
1. Probably Your charset is wrong (after PHP 5.5)
– Set charset after open tag:

header('Content-Type: text/html; charset=utf-8');

– And set charset utf8 in your database :

mysql_query("SET NAMES 'utf8'");

2. Your serialized array is faulty
Could be fixed by:

$fixed_data = preg_replace_callback ( '!s:(\d+):"(.*?)";!', function($match) {      
    return ($match[1] == strlen($match[2])) ? $match[0] : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
},$bad_data );

Or by:

function repairSerializeString($value)
{

    $regex = '/s:([0-9]+):"(.*?)"/';

    return preg_replace_callback(
        $regex, function($match) {
            return "s:".mb_strlen($match[2]).":\"".$match[2]."\""; 
        },
        $value
    );
}

(Both functions and authors can be found on page http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset)
3. There is sth else like corrupt data or sth similar…

Leave a Reply

Your email address will not be published. Required fields are marked *