Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL String Object to PHP array conversion

Tags:

php

mysql

I have this object string in my MySQL database and I need to convert it to a PHP array. I believe it's a multi-level Object, but I'm unsure on how to parse it into a usable array.

a:11:{s:7:"version";s:3:"4.3";s:9:"increment";i:2;s:7:"convert";b:0;s:7:"dynamic";b:0;s:8:"gestures";b:0;s:9:"integrate";b:0;s:9:"shortcuts";b:0;s:9:"uninstall";b:0;s:5:"sizes";a:0:{}s:5:"terms";a:0:{}s:11:"collections";a:1:{s:9:"webcomic1";a:15:{s:2:"id";s:9:"webcomic1";s:4:"name";s:13:"Feedback Inc.";s:5:"image";s:1:"0";s:5:"theme";s:29:"twentyfourteen|twentyfourteen";s:7:"updated";i:1427408379;s:8:"supports";a:9:{i:0;s:5:"title";i:1;s:7:"excerpt";i:2;s:6:"editor";i:3;s:9:"thumbnail";i:4;s:8:"comments";i:5;s:10:"trackbacks";i:6;s:9:"revisions";i:7;s:13:"custom-fields";i:8;s:6:"author";}s:10:"taxonomies";a:2:{i:0;s:8:"category";i:1;s:8:"post_tag";}s:11:"description";s:0:"";s:5:"feeds";a:3:{s:4:"hook";b:1;s:4:"size";s:4:"full";s:4:"main";b:1;}s:5:"slugs";a:5:{s:4:"name";s:8:"feedback";s:7:"archive";s:8:"feedback";s:8:"webcomic";s:8:"feedback";s:9:"storyline";s:8:"feedback";s:9:"character";s:8:"feedback";}s:6:"buffer";a:3:{s:4:"hook";b:1;s:4:"days";i:7;s:5:"email";s:25:"[email protected]";}s:6:"access";a:4:{s:5:"byage";b:0;s:6:"byrole";b:0;s:3:"age";i:18;s:5:"roles";a:1:{i:0;s:1:"!";}}s:7:"twitter";a:8:{s:5:"media";b:0;s:6:"format";s:39:"%collection-name has updated! %site-url";s:11:"oauth_token";s:0:"";s:12:"oauth_secret";s:0:"";s:12:"consumer_key";s:0:"";s:15:"consumer_secret";s:0:"";s:13:"request_token";s:0:"";s:14:"request_secret";s:0:"";}s:8:"commerce";a:9:{s:8:"business";s:0:"";s:8:"currency";s:3:"USD";s:6:"method";s:7:"_xclick";s:8:"donation";i:0;s:5:"price";a:3:{s:8:"domestic";i:6;s:13:"international";i:9;s:8:"original";i:12;}s:8:"shipping";a:3:{s:8:"domestic";i:4;s:13:"international";i:6;s:8:"original";i:8;}s:6:"prints";b:0;s:9:"originals";b:0;s:5:"total";a:3:{s:8:"domestic";d:10;s:13:"international";d:15;s:8:"original";d:20;}}s:11:"transcripts";a:4:{s:4:"open";b:1;s:9:"languages";a:1:{i:0;s:1:"!";}s:10:"permission";s:8:"register";s:6:"notify";a:2:{s:4:"hook";b:1;s:5:"email";s:25:"[email protected]";}}}}}

Could someone:

  1. itentify what type of string this is?
  2. Explain how to parse it into a usable PHP array?
like image 446
Mark Larson Avatar asked Mar 27 '15 23:03

Mark Larson


1 Answers

That's the format that serialize() produces. Use unserialize to parse it into an array.

$array = unserialize($string);

It's irrelevant that it came from MySQL.

like image 87
Barmar Avatar answered Sep 22 '22 14:09

Barmar