A
A
Artem Prokhorov2021-06-21 15:27:47
PHP
Artem Prokhorov, 2021-06-21 15:27:47

How to add/change file text with file_put_contents in the middle of content?

For example, there is a json file with the following content:

[
  {
    "some": 1
  }
]


How can I change to ? "some": 1"some": 2

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pLavrenov, 2021-06-21
@kotcich

file_put_contents - writes to a file. So take what you write to a file and replace it as in normal json.

A
Alexander Aksentiev, 2021-06-21
@Sanasol

1. Read the file
2. Parse json
3. Change the required data
4. Convert json to a string
5. Write to file
No modification in the middle of the file will work, only overwrite the entire file. Especially json.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question