Weird question, every time i save ids of users in

my json file with php, they just disappear, have someone faced something like that?

10 ответов

30 просмотров

What code?

A- Автор вопроса
Shrimadhav U K
What code?

function save($data = [], $path) // USED TO SAVE IN msgsSet { file_put_contents($path, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); } $arrayuser[] = 123; $myhumblepath = "file.json"; save($arrayuser, $myhumblepath);

A
function save($data = [], $path) // USED TO SAVE I...

it will overwrite each time? Right? maybe you need to get the existing data, and then append 😅🤔

A- Автор вопроса

❌❌

A
❌❌

file_put_contents is fine. As far as I can see your code makes your file contain the following content: [123] Is that what's happening and/or expected?

A- Автор вопроса
A- Автор вопроса

the file after a while getting empty (null)

A
the file after a while getting empty (null)

So the file size is 0 because its empty? Or is the file size 4 bytes because it contains null?

A- Автор вопроса
A
0 empty

If json_encode() fails, it returns false. You could try to use the flag JSON_THROW_ON_ERROR. Maybe the error message will tell you, why it fails.

Похожие вопросы

Карта сайта