在txt文件中添加换行符不起作用

时间:2014-02-05 01:28:48

标签: php text line break

我有一个php文件,它将点击曲目数据添加到.txt文件中。问题是,每次添加数据时,它都会添加到同一行,即使我添加了"r\n"

<?php
    $src = isset($_GET['src']) ? $_GET['src'] : "-";
    $dst = isset($_GET['dst']) ? $_GET['dst'] : "-";
    $f = fopen('clickReport.txt',"a+");
    fwrite ($f, date('Y-m-d H:i'));
    fwrite ($f, " : " + $src + " : " + $dst + "\r\n");
    fclose($f);
?>

文本文件输出:

2014-02-05 01:1702014-02-05 01:1702014-02-05 01:1702014-02-05 01:170

我当然希望如此:

2014-02-05 01:170
2014-02-05 01:170
2014-02-05 01:170
2014-02-05 01:170

等...

1 个答案:

答案 0 :(得分:0)

尝试替换此行:

fwrite ($f, " : " + $src + " : " + $dst + " _ " + "\r\n");

用这个:

fwrite ($f," : ".$src." : ".$dst." _ "."\r\n");