Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this encoding called?

Tags:

php

I see it in Wordpress in the database and i now see similar in a cookie. What kind of parser parses this:

a:4:{s:14:"clientsorderby";s:9:"firstname";s:12:"clientsorder";s:4:"DESC";s:13:"ordersorderby";s:2:"id";s:11:"ordersorder";s:4:"DESC";}

I get it, its a=array:x=number of children s=string:x=number of characters.

Is there a parser built into php for this kind of thing? why do they use this method?

like image 329
Emery King Avatar asked Sep 06 '26 04:09

Emery King


1 Answers

It's PHP's built-in serialize(), which can be "decoded" with unserialize()

Here is an example:

$serialized = 'a:4:{s:14:"clientsorderby";s:9:"firstname";s:12:"clientsorder";s:4:"DESC";s:13:"ordersorderby";s:2:"id";s:11:"ordersorder";s:4:"DESC";}';
$unserialized = unserialize( $serialized);

var_dump( $unserialized);

Output:

array(4) {
  ["clientsorderby"]=>
  string(9) "firstname"
  ["clientsorder"]=>
  string(4) "DESC"
  ["ordersorderby"]=>
  string(2) "id"
  ["ordersorder"]=>
  string(4) "DESC"
}
like image 154
ziad-saab Avatar answered Sep 07 '26 21:09

ziad-saab



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!