I have this array:
$array = '[[Smarties, 50g, 3, 1.99],
[M&Ms Peanut, 49g, 3, 1.99],
[Oreo Cookies, 300g, 1, 3.99],
[Pepsi, 355ml, 3, 1.29]]';
I need to use json_decode, so I need to find a way to surround the information inside in quotes like this:
[["Smarties", "50g", "3", "1.99"],
["M&Ms Peanut", "49g", "3", "1"."99"],
["Oreo Cookies", "300g", "1", "3.99"],
["Pepsi", "355ml", "3", "1.29"]]
I tried using preg_replace, and this is what I'm currently getting (close, but it's separating the prices into two and also separating two-word names into two.):
[["Smarties", "50g", "3", "1"."99"],
["M"&"Ms" "Peanut", "49g", "3", "1"."99"],
["Oreo" "Cookies", "300g", "1", "3"."99"],
["Pepsi", "355ml", "3", "1"."29"]]
I'm having a really hard time understanding preg_replace and I'm hoping someone might be able to help.
Is there a way to use the separating commas as guides to determine where to put the quotes?