Hello, help me figure it out. Here is the code:

function razdel() { $file = file("ancorrzd.txt"); foreach($file as $str_number => $str_content) { echo "строка " . ($str_number + 1) . " : " . $str_content; } $file = fopen ("rzd.txt","w"); $str = "$str_conten"; fputs ( $file, $str); fclose ($file); 

Displays lines from ancorrzd.txt. Suppose the script is executed n times. It is necessary that every time you run in rzd.txt recorded all new line. Here is the link to the whole script.

  • If it's not a secret, why execute the script several times? - ling
  • Generally meaningless, some kind of script you have. It is better to explain in words what you are trying to implement. - Ilya Pirogov
  • There is a file with many lines, each line is the name for the future file, that's all. - multidor

4 answers 4

fopen ()

You need to the stream. It may be any of the following:

  • 'a' - Open for writing only; place the file . If the file doesn’t exist, attempt to create it.

    there is a file with many lines, each line is the name for the future file, that's all.

     function razdel() { $file = file("ancorrzd.txt"); // получаем названия файлов foreach($file as $name) // пробегаемся по ним циклом { $fp = fopen(trim($name), 'w'); // создаем файл fclose($fp); // и оставляем его в покое } } 

    Did I understand you correctly?

    • Now I do not understand you. - multidor
    • Added comments. - ling
    • Thanks for the replies, but still nothing works. - multidor
      function razdel() { if(file_exists("rzd.txt")) $file1_c = count(file("rzd.txt")); $file = file("ancorrzd.txt"); $fp = fopen("rdz.txt","a+"); fputs($fp,$file[$file1_c]); fclose($fp); 

    maybe so?

    • so it’s like that, only rzd.txt recorded all the lines at once, but only one is needed, and then when the next interaction starts in the loop, you need to write the line number 2, then 3, etc. - multidor
    • rewrote - or_die
    • You have a mistake - rdz.txt, corrected m, everything worked, THANKS !!! - multidor
    • one
      Well, if it worked, then to the left of the answer there is such a button with a check mark). - ling
     fputs($file,each(file('из какого файла'))); 

    - something like this.