PHP_EOL和" \ n"将第1行留空

时间:2017-12-27 21:16:13

标签: php blank-line

我有保存数据的简单代码:

$data = $_POST["data"];
$userID = $_POST["userID"]; 

if (empty($data)){
   } else {
    $theFile = fopen("Data/" . $userID . ".txt", "a+");
    fwrite($theFile, PHP_EOL.$data);
    fclose($theFile);      
}

数据可以很好地保存数据,但始终是第1行的空行。我已尝试切换到" \ n"问题仍然存在。还有什么我可以尝试的吗?

1 个答案:

答案 0 :(得分:5)

变化:

fwrite($theFile, PHP_EOL.$data);

使用:

fwrite($theFile, $data.PHP_EOL);

否则你的第一行是空的,因为第一个写的字符是\ n

相关问题