如何开始新的生产线?

时间:2016-04-13 19:14:44

标签: php

我想写一个新行,但它只是写在行的末尾而不是开始新行。我有一个问题:如何解决这个问题?

<?php

if (isset($_POST['submit'])){
$data=array($_POST['name'].",", $_POST['genger'].",",$_POST['age']."," ,$_POST['personalitytype']."," ,$_POST['OS']."," ,$_POST['min']."," , $_POST['max']);

file_put_contents('singles.txt', $data, FILE_APPEND);
}
?>

2 个答案:

答案 0 :(得分:4)

尝试在数组的最后位置加上分界线\r\n

答案 1 :(得分:2)

您需要内爆数组(一旦修复了连接语法错误)并在内爆行的末尾添加换行符:

if (isset($_POST['submit'])){
$data=array($_POST['name'].",". $_POST['genger'].",".$_POST['age'].",". $_POST['personalitytype'].",".$_POST['OS'].",".$_POST['min'].",". $_POST['max']);
$line = implode(',', $data)."\n"; // creates a comma separated line with a line break at the end

file_put_contents('singles.txt', $line, FILE_APPEND);
}