PHP 写入文本文件

PHP Write To Text File

当我写入文本文件时,所有数据都打印在第一行,虽然我使用了PHP_EOL,但我想逐行打印。

            $file_Name = './textFilesData/Accounts_Deafult_Data.txt';
            $current = file_get_contents($file_Name);
            $c = 0;

            while ( $c < 5 )
                {
                    $current = 'Rafat';
                    $current = $current.PHP_EOL;    

                    $c++;
                }
            file_put_contents($file_Name, $current);

您可以使用: $current = "$current1\n";

  $file_Name = './textFilesData/Accounts_Deafult_Data.txt';
            $current = file_get_contents($file_Name);
            $c = 0;

            while ( $c < 5 )
                {
                    $current1 = 'Rafat';
                    $current .= "\n$current1";    

                    $c++;
                }
            file_put_contents($file_Name, $current);

使用这个,

$current .= "Rafat";

添加 \r\n 应该有效

$file_Name = './textFilesData/Accounts_Deafult_Data.txt';
            $current = file_get_contents($file_Name);
            $c = 0;

            while ( $c < 5 )
                {
                    $current .= 'Rafat'."\r\n";    

                    $c++;
                }
            file_put_contents($file_Name, $current);