1

Well, I made a code that returns that serializated data:

a:3:{i:0;s:250:"Sistema Operativo: Windows Vista SP1 / Windows XP SP3
Procesador: Intel Core 2 Duo 1.8 Ghz, AMD Athlon X2 64 2.4 Ghz
Memoria: 1.5GB Windows Vista / 1GB Windows XP
Espacio en Disco: 16GB libres
Gráfica: 256MB NVIDIA 7900 / 256MB ATI X1900";i:1;s:281:"Sistema Operativo: Windows Vista SP1 / Windows XP SP3
MicroProcesador: Intel Core 2 Quad 2.4Ghz, AMD Phenom X3 2.1Ghz
RAM: 2.5GB Windows Vista / 2.5GB Windows XP
Espacio en Disco: 18GB libres
Gráfica: 512 MB NVIDIA 8600 / 512MB ATI 3870
Otros: DVD-ROM de doble capa";i:2;s:0:"";}

But when I unserialize it, it only returns 1...

I don't know why...

I use $data = (array)unserialize($quote); but I had that weird problem that I don't know how to solve... :'(

EDIT:

There is my serialized variable $finalreq = serialize(array(0 => $minreq, 1 => $req, 2 => $maxreq)); $minreq, $req and $maxreq is a $_POST variable.

SOLVED:

If it happens to you the only thing you have to do is use a special function for UTF-8 characters called muti-byte unserialization.

The code:

/**
 * Mulit-byte Unserialize
 *
 * UTF-8 will screw up a serialized string
 *
 * @access private
 * @param string
 * @return string
 */
function mb_unserialize($string) {
    $string = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $string);
    return unserialize($string);
}

The original post: https://stackoverflow.com/a/5813058/3286975

Thanks.

Community
  • 1
  • 1
z3nth10n
  • 2,341
  • 2
  • 25
  • 49
  • Is your string ok? I have: `PHP Notice: unserialize(): Error at offset 266 of 551 bytes` – Artur Feb 22 '14 at 23:50
  • I echo it before, and It returns me that... But any errors appears at unserialization of that string it only returns 1. :( – z3nth10n Feb 22 '14 at 23:52
  • Please check if `serialize($your_object);` is the same string as above. – Artur Feb 22 '14 at 23:53

1 Answers1

1

It's actually returning false, because it's throwing an error:

Notice: unserialize() [function.unserialize]: Error at offset 266 of 551 bytes

var_dump-ing the results returns bool(false) due to the error.

Did you alter the information after serializing? Serialized data is picky. In your data above:

a:3:{i:0;s:250:
  1. The a:3 says "it's an array, with 3 elements"
  2. The { indicates the start of the first element.
  3. The i:0 indicates the index is zero.
  4. The s:250 indicates that the next 250 characters are the value.

If you've changed the length in any way, the parser can't properly unserialize, because it's expecting 250 characters....

random_user_name
  • 25,694
  • 7
  • 76
  • 115
  • Its look like a bug, because I only use a serialize function for get that weird string... So what can I do? – z3nth10n Feb 23 '14 at 00:16
  • I solved it using that: http://stackoverflow.com/a/5813058/3286975 Thanks anyway for the guide. :P – z3nth10n Feb 23 '14 at 00:37