Answer the question
In order to leave comments, you need to log in
What is the correct way to perform this task in php?
I can’t solve this problem, the fact is that there are 100 .txt files in one folder, you need to open them one by one, decode the array from where and perform further actions with it, then save it all to another file.
That's how I did it
$nm = 'tm-contents/e0.txt';
$homepage = file_get_contents($nm);
$ins = json_decode ( $homepage , true);
for ($i=1; $i <= 500; $i++) {
//Тут код который не имеет отношения к вопросу
//Сохраняем после редактирования
$json= json_encode($rs);
$nextNameFisier = 'rs/alx'.$i.'.txt';
$f = fopen($nextNameFisier, "w");
fwrite($f, $json);
fclose($f);
}
Answer the question
In order to leave comments, you need to log in
you need to use foreach like this
foreach (glob('tm-contents/*.txt') as $filename) {
$fileId = preg_replace('~\D~','',$filename); // удаляем все кроме цифр
$data = json_decode(file_get_contents('tm-contents/'.$filename));
foreach ($data as $key=>$arr) {
// секретные действия с $data
}
file_put_contents ('rs/alx'.$fileId.'.txt', json_encode($data));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question