Reputation: 3226
I keep product options as string in DB, and I need to parse it (string to array).
String is:
{option_name:option_id{variant_id:variant_name}}
How can I parse it with using PHP?
Upvotes: 0
Views: 295
Reputation: 48887
You didn't detail the field formats so here's a guestimate that you can tweak:
preg_match('/^{(\w+):(\d+){(\d+):(\w+)}}$/', '{an_option_name:123{456:a_variant_name}}', $matches);
$option_name = $matches[1];
$option_id = $matches[2];
$variant_id = $matches[3];
$variant_name = $matches[4];
Upvotes: 1