Clear json file

Hello.

I have an delete button in the index.php page like this.

/form

form method="POST" action="deleteall.php"

input type="submit" value="delete" name="delete"

/form

I send it to deleteall.php and there i want to clear the json-file “todolist.json” to an empty array.

How do i do this?

Hi @Andyphp!

Have you tried something like:

file_put_contents("todolist.json", json_encode([]));

That did the work!
It looks so easy but ben struggling with this all day.

Appreciate the help. Thanks alot!

1 Like

Glad to help :slight_smile:

If you have any other question, feel free to ask

Sponsor our Newsletter | Privacy Policy | Terms of Service