2016-01-05 50 views
1

我嘗試在寫入條目時寫入新行文本我現在無法使用達時使用時間日期當新條目創建時它將接下來到舊的入口。PHP在新行中添加新文本的文本

05-01-2016, 16:33 - 2016-01-05 04:01:1905-01-2016, 16:33 - 2016-01-05 04:01:20 -01-05 04:01:14a2016-01-05 04:01:15a2016-01-05 04:01:15a2016-01-05 04:01:16

$timezone = "Asia/Colombo"; 
    date_default_timezone_set($timezone); 
    $today = date("Y-m-d h:m:s"); 
    echo $today; 

    $myfile = fopen("D:\Log\log.txt", "a") or die("Unable to open file!"); 
$txt = "user id date"; 
fwrite($myfile, "a". $today ."\n"); 
fclose($myfile); 
+2

使用'PHP_EOL'新線 – Saty

回答

1

使用FWRITE與PHP_EOL

fwrite($myfile, "a". $today .PHP_EOL); 

如果不工作,您可以嘗試

fwrite($myfile, "a". $today ."\r\n"); 
0
$file  = "/your_file_path/your_file_name.txt"; 
file_put_contents($file, print_r($your_content, true), FILE_APPEND); 

先設置你的文件的路徑和附加到您的新的內容FILE_APPENDfile_put_contents並授予您存儲文件的文件夾的權限。

0

你可以使用這個代碼,它工作得很好:

fwrite($myfile, "\r\n"."a".$today); 
相關問題