[JavaScript] [PHP] Write string to a config file, should be formatted as an Array

Hi All,

What i want to do is the following,
i want to write my config back to the configfile (smartmirror project with a configpage)
commented part is where my string is written back via send.php.
What is missing? the Array_Keys at item 4 (URL2)
And also the brackets inbetween },{

I hope that there is someone who can assist me.
(By the way, Openhab-Addon is planned)
Some links are shortened (full code on Github)
Link to the Repo


calendars: [
 {url: "URL1",color: "#ffffff",slice: "99"},
{url: "URL2",color: "#00ff00",slice: "99"} ],

//written back
//calendars: [
//{url: "URL1",color: "#ffffff",slice: "99",: "URL2",: "#00ff00",: "99}],


$calendar['feed'] = "{" . implode('",', array_map(function ($v, $k) { return $k . ': "' . $v; }, $_GET['calfeed'], array_keys($a))) . "}";


In your php seems you are missing the " around the {

“{” should probably work.


Well, the unquoted { and } are part of the function. I can not add a quote.

$elements = array();
foreach (array_chunk($_GET['calfeed'], 3) as $section) {
$elements[] = implode('",', array_map(function ($v, $k) { return $k . ': "' . $v; }, $section, array_keys($calkeys)));
$calendar['feed'] = "{" . implode( '"},'."\n\t\t\t".'{'  ,$elements) . '"}';

Is my approach now. It works like expected. Linefeed has been added. I’ll upload it on github soon.
Only adding more calendar Feeds will cause some problems at the moment.

ok - cool - as what was missing in the output had been the {

good it works now.