This question is not related at all to the mentioned duplicate answer/question...
I have a large list of over 1,000 items in JavaScript i this format...
var plugins = [
{
name: "Roundabout - Interactive, turntable-like areas",
url: "http:\/\/fredhq.com/projects/roundabout/",
tag: "slide"
},
{
name: "Slides - Simple slideshow plugin for jQuery",
url: "http://slidesjs.com/",
tag: "slide"
}
......lots more
]
My goal is to import them into a PHP array like this....
Array
(
[0] => Array
(
[name] => Roundabout - Interactive, turntable-like areas/
[url] => http://fredhq.com/projects/roundabout/
[tag] => slide
)
[1] => Array
(
[name] => Slides - Simple slideshow plugin for jQuery
[url] => http://slidesjs.com/
[tag] => slide
)
[2] => Array
(
[name] => Orbit - jQuery Image Slider Plugin
[url] => http://www.zurb.com/playground/jquery_image_slider_plugin/
[tag] => slide
)
)
I tried using PHP's json_decode() function however the source JS does not have the keys wrapped in " so it does not work.
When I manually added "'s around the keys and some backslashes then PHP json_decode() works....
$json = '[{
"name": "Roundabout - Interactive, turntable-like areas/",
"url": "http:\/\/fredhq.com/projects/roundabout/",
"tag": "slide"
},
{
"name": "Slides - Simple slideshow plugin for jQuery",
"url": "http:\/\/slidesjs.com\/",
"tag": "slide"
},
{
"name": "Orbit - jQuery Image Slider Plugin",
"url": "http:\/\/www.zurb.com/playground/jquery_image_slider_plugin/",
"tag": "slide"
}]';
echo '<pre>';
print_r(json_decode($json, true));
echo '</pre>';
The issue though is my large list does not have the keys wrapped in quotes so I need a way to automate it.
Could someone help me to achieve the end goal since my attempts have all failed so far please?
JSON.stringify(obj)in your object before the PHP functionjson_decode.