How to write strings in foreach?

Hello, help me understand. 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. Let’s assume that the script will be executed n times. It is necessary that every time it is run, a new line is written to rzd.txt.
Here is linkto the whole script.

Answer 1, authority 100%


The modeparameter specifies the type of access you require to the stream. It may be any of the following:

  • 'a'– Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.

Answer 2, authority 100%

there is a file with many lines, each line is a 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?

Answer 3, authority 100%

function razdel() 
        $file1_c = count(file("rzd.txt"));
    $file = file("ancorrzd.txt");
    $fp = fopen("rdz.txt","a+");

Maybe so?

Answer 4

fputs($file,each(file('  ')));

– something like this.