PHP 写入文本文件 [英] PHP Write To Text File
本文介绍了PHP 写入文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我写入文本文件时,所有数据都打印在第一行,虽然我使用了 PHP_EOL,但我想逐行打印.
When I write to text file , all data printed on first line , although I used PHP_EOL , I want to print it line by line.
$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);
推荐答案
添加 \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);
这篇关于PHP 写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文