I have the below formatted code from database.
a:9:{i:8053;a:26:{s:4:"name";s:0:"";s:12:"squareseaten";s:0:"";s:4:"wins";s:0:"";s:9:"timetaken";s:0:"";s:10:"tubeseaten";s:0:"";s:12:"gummieseaten";s:0:"";s:12:"pepperseaten";s:0:"";s:10:"chipseaten";s:0:"";s:13:"bottlechugged";s:1:"1";s:17:"boxesofbiteseaten";s:0:"";s:19:"boxesofbrutalseaten";s:0:"";s:14:"crunchieseaten";s:0:"";s:17:"boxesofdncvseaten";s:0:"";s:15:"bottlesconsumed";s:0:"";s:12:"pieceschewed";s:0:"";s:14:"additionalnuts";s:1:"1";s:15:"additionaltimes";s:0:"";s:18:"additionalattempts";s:0:"";s:3:"pts";s:0:"";s:1:"p";s:0:"";s:1:"w";s:0:""; ...
This looks like JSON. But it’s not actually.
This was actually generated by a WordPress plugin called wpDataTables.
How can I parse through this data in PHP?
2
Answers
That’s a serialized string. Run that string through
unserialize()
and you’ll get an array.This is a serialized string you need to use unserialize()
Ex:
Output
The unserialize() function converts serialized data into array.
Syntax:
string(Required): Specifies the serialized string.
options : Specifies options to be provided to the function, as an associative array. Can be either an array of class names which should be accepted, false to accept no classes, or true to accept all classes. True is default.