How do I unserialize and then convert the resulting multidimensional array into plain text, stripped of code?

  json, php, wordpress

Thank you in advance of any help on this. I’m trying to export some product specs from a WordPress site to a spreadsheet with WP All Export which allows the use of PHP filters, and we want it to export as easily readable text. The specifications live in a custom WP field which exports as a serialized array. I’m not at all well-versed in PHP, but I think I need to unserialize the WP field contents into an array and then I need to convert the resulting array into as close to a simple string as possible. Is this possible? Here is an example of one of the fields I need to convert:


a:3:{s:6:"header";b:0;s:7:"caption";b:0;s:4:"body";a:4:{i:0;a:2:{i:0;a:1:{s:1:"c";s:9:"Materials";}i:1;a:1:{s:1:"c";s:26:"Steel alloy";}}i:1;a:2:{i:0;a:1:{s:1:"c";s:6:"Weight";}i:1;a:1:{s:1:"c";s:18:"2.25 lbs";}}i:2;a:2:{i:0;a:1:{s:1:"c";s:6:"Length";}i:1;a:1:{s:1:"c";s:16:"6.32 in";}}i:3;a:2:{i:0;a:1:{s:1:"c";s:20:"Applicable Standards";}i:1;a:1:{s:1:"c";s:46:"Meets OSHA xxx, ANSI xxx";}}}}


..to ideally look something like this:


Materials: Steel alloy,
Weight: 2.25 lbs,
Length: 6.32 in,
Applicable Standards: Meets OSHA xxx, ANSI xxx


Source: Ask PHP

LEAVE A COMMENT