怎么打破一行代码

时间:2014-02-09 05:37:54

标签: php html line break

我试图在此代码之后打破这一行。我无法弄明白我的代码输出如下所示:

输出:

  

用户:admin登录:2014-02-09 05:34:30用户:adminLogged OUT:   2014-02-09 05:34:36用户:tata登录于:2014-02-09 05:34:41用户:   tataLogged OUT:2014-02-09 05:34:43

我想设置一些空格和新线。

$date=date("Y-m-d H:i:s");
$updatefile = "userlogs.txt";  
$fh = fopen($updatefile, 'a') or die("can't open file");
$stringData = "User: $username";
fwrite($fh, "$stringData");
$stringData = "Logged in: $date";
fwrite($fh, "$stringData");
fclose($fh);

2 个答案:

答案 0 :(得分:1)

只需在\n前面使用\rfwrite()

喜欢这个。

fwrite($fh, "\n$stringData");
              ^-------- // Add this to both of your fwrite() calls

答案 1 :(得分:0)

试试这个

$date = date("Y-m-d H:i:s");
$updatefile = "userlogs.txt";  
$fh = fopen($updatefile, 'a') or die("can't open file");
$stringData = "User: $username";
fwrite($fh, "$stringData\n");
$stringData = "Logged in: $date";
fwrite($fh, "$stringData\n");
fclose($fh);

您只需在变量分配之前或之后添加\n,就像fwrite($fh, "$stringData\n");fwrite($fh, "\n$stringData");一样。

有关详细信息,请参阅this question