I was just wondering if anyone in the community had something to read the PHP serialized array string data format.
They look like this:
Which roughly converts into:
Array of length One: (Index 0) of Array is a (String of length 1) with a value of “2”
But they get longer and more complicated obviously.
Here’s an example of a larger one in the DB:
a:10:{i:0;s:24:"group_pages_menu_metabox";i:1;s:31:"user_profile_pages_menu_metabox";i:2;s:23:"add-buddypress-nav-menu";i:3;s:19:"add-post-type-forum";i:4;s:21:"add-post-type-project";i:5;s:31:"add-post-type-profilegrid_blogs";i:6;s:12:"add-post_tag";i:7;s:15:"add-post_format";i:8;s:20:"add-project_category";i:9;s:15:"add-project_tag";}
As you can see it is not quite JSON but has similarities. Just trying to find the easiest way to convert this into something easily readable/usable in Xojo, whether that means stripping it and building a JsonItem or Variants I’m not too picky. Any thoughts or suggestions would be appreciated.
I don’t have PHP in scope and I’m getting these values directly from a MySQL DB. Even some stored_proc in MySQL to convert it to Json would work so I could read it on the Xojo side
If you have MBS, its PHP functions could help. I used MBS PHP to convert human dates into SQL Dates which was much cleaner than the Xojo Date classes.
Unfortunately no and I’d rather avoid using MBS for this project
I found this website that does it:
http://solutions.weblite.ca/php2json/index.php
But unfortunately I need to do it in code and not through a helper site
[quote=490460:@Hal Gumbert]Can you use javascript in an HTMLViewer?
https://stackoverflow.com/questions/14227388/unserialize-php-array-in-javascript[/quote]
Unfortunately the “serialize” and “unserialize” are PHP specific commands not available in javascript.
I decided to make the Wordpress PHP side duplicate all the settings I need in the database with a “_json” suffix so I can read them easier:
$setting = get_user_meta($user_ID, $setting_name, true);
$setting_json= json_encode($pm_group);
update_user_meta($user_ID, $setting_name."_json", $setting_json);
Seems like you could extract the string from between the { and } chars, split it using the ; character and then parse each one… especially if they always come in threes.
[quote=490475:@Hal Gumbert]Hey Brock,
Norm wrote one: https://ifnotnil.com/t/perfect-use-for-finite-state-machines/520[/quote]
Awesome, that helps! Thank Hal and thanks Norm!