Hello,
i need to make a external script that read only the value of product attribute from #__virtuemart_order_items table.
this is my product_attribute string value:
{
"1": {
"2": {
"comment": "AJ4F9F"
}
}
}
Well, i need to extract from this string only AJ4F9F.
How can i do this?
thanks!
I tried with this code:
$stringa = '{
"1": {
"2": {
"comment": "AJ4F9F"
}
}
}';
preg_match_all('/".*"/', $stringa, $ris);
$a= $ris[0][2];
$data = explode(':', $a);
echo str_replace('"','',$data[1]);
But i don't know if this is the right solution.
Can anyone help me?
Thank you!
That's probably JSON data. Use json_decode to turn it into object or array.
This works if you just need to echo the comment once:
echo json_decode($stringa,true)[1][2]['comment'];
Thank you for suggestion.
Now i used this code:
$data_attribute = json_decode($product_attribute, true);
$code = $data_attribute ['1']['2']['comment'];
and seem it works.
Thank you so much!