I'm sending the following string trough a javascript function into a PHP file:
function showcart()
{
document.getElementById('cart').value = JSON.stringify(paypal.minicart.cart.items());
}
On PHP side the string comes as follows:
echo $_POST['cart'];
[{"_data":{"cmd":"_cart","add":"1","item_name":"FILA 1010302","item_image":"images/1010302-1.png","amount":99,"discount_amount":"50.00","submit":"Adicionar ao carrinho","quantity":2,"href":"http://teste/index.html#5"},"_options":[],"_discount":100,"_amount":99,"_total":98,"_eventCache":{"change":[[null,null]]}},{"_data":{"cmd":"_cart","add":"1","item_name":"FILA 1010575","item_image":"images/1010575-1.png","amount":99,"discount_amount":"50.00","submit":"Adicionar ao carrinho","quantity":1,"href":"http://teste/index.html#5"},"_options":[],"_discount":50,"_amount":99,"_total":49,"_eventCache":{"change":[[null,null]]}},{"_data":{"cmd":"_cart","add":"1","item_name":"FILA 1010707","item_image":"images/1010707-1.png","amount":99,"discount_amount":"50.00","submit":"Adicionar ao carrinho","quantity":1,"href":"http://teste/index.html#5"},"_options":[],"_discount":50,"_amount":99,"_total":49,"_eventCache":{"change":[[null,null]]}},{"_data":{"cmd":"_cart","add":"1","item_name":"FILA SCM00514","item_image":"images/scm00514-1.png","amount":99,"discount_amount":"50.00","submit":"Adicionar ao carrinho","quantity":1,"href":"http://teste/index.html#5"},"_options":[],"_discount":50,"_amount":99,"_total":49,"_eventCache":{"change":[[null,null]]}}]
What I'm looking for is to save each field into separate variables, for example:
item = 1 item_name = FILA 1010302, item_image = images/1010302-1.png quantity = 2
item = 2 item_name = FILA 1010575, item_image = images/1010575-1.png quantity = 1
I'm trying several ways using json_decode and html_entity_decode but I just can't reach the desired output.
Can someone help me on this, I'm assuming this is a fairly easy task, but I'm new to PHP, please try to understand.
Thank you in advance!
item_name,item_imageetc. in there.