I try to add data to a json file.
First try:
$filename = "$root/nachrichten/bla.json";
$neueartikel = json_decode(file_get_contents($filename), true); /*until here everything works, I can loop the file*/
$neueartikel[] = array('titel' => 'bla',
'bild' => 'bla',
'url' => 'bla',
'ID' => 'bla',
'bildserver' => 'bla');
file_put_contents('$root/nachrichten/bla.json', json_encode($neueartikel);
Second try:
$filename = "$root/nachrichten/bla.json";
$neueartikel = json_decode(file_get_contents($filename), true);
$neu[] = array('titel' => 'bla',
'bild' => 'bla',
'url' => 'bla',
'ID' => 'bla',
'bildserver' => 'bla');
$result = array_merge($neueartikel, $neu);
file_put_contents('$root/nachrichten/bla.json', json_encode($result);
How can I do this right????
UPDATE:
I also tryed what PotatoIng sayd:
$filename = "$root/nachrichten/bla.json";
$temparray = json_decode(file_get_contents($filename), true);
$neu = array('titel' => 'bla',
'bild' => 'bla',
'url' => 'bla',
'ID' => 'bla',
'bildserver' => 'bla');
array_push($temparray, $neu);
file_put_contents("$root/nachrichten/bla.json", json_encode($temparray);
Still nothing (ignore this text I need to add some or else I can't submit -.-)