Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用户输入写入文件表单上的一种间隔条目_Php_Html - Fatal编程技术网

Php 用户输入写入文件表单上的一种间隔条目

Php 用户输入写入文件表单上的一种间隔条目,php,html,Php,Html,当用户键入一个句子并按下“添加文本”按钮时,我有一个代码 然后文本被发送到一个文件中 这是密码 <html> <head> <title>Write to a text file</title> </head> <body> Put Cataline/page.txt furni info, <form action="" method='post'> <input name='textblock'&g

当用户键入一个句子并按下“添加文本”按钮时,我有一个代码 然后文本被发送到一个文件中

这是密码

<html>
<head>
<title>Write to a text file</title>
</head>
<body>

Put Cataline/page.txt furni info, 
<form action="" method='post'>
<input name='textblock'></input>
<input type='submit' value='Add text'>
</form>

<?php

// Open the text file
$f = fopen("textfile.txt", "a");

// Write text
fwrite($f, $_POST["textblock"]); 

// Close the text file
fclose($f);

// Open file for reading, and read the line
$f = fopen("textfile.txt", "r");

// Read text
echo fgets($f); 
fclose($f);

?>

</body>

</html>

写入文本文件
放置Cataline/page.txt furni信息,
它很好用。有一个问题

我将用一个例子来说明这一点

User1:Oo我可以在这里上传我的furnidata好的,我会做的,输入furnidata T (User1的furnidata(他想要添加的文本)被发送到文件…(它可以工作)

现在出现了user2

User2:轮到我添加furni数据了(与user1的操作相同,它会上传到文件中,工作正常)

但是

这就是代码的样子

user1funidatatatatblahblahblahendofdatauser2funidatablahblahendofdata

这就是我想要的样子

user1funidatatatatblahblahblahendofdata
user2furnidatablahblahendofdata


有人能建议我做到这一点吗?

只要在每篇文章后面写一行新行就行了,这不是很难吗?

这可以通过在每个用户的“furni数据”后面添加\r\n来实现吗?这很可能会创建一行新行

fwrite($f,$\u POST[“textblock”]。“\r\n”);

给你:

PHP/HTML:

<html>
<head>
    <title>Write to a text file</title>
</head>
<body>

Put Cataline/page.txt furni info,
<form action="" method="post">
    <input type="text" name="text"></input>
    <input type="submit" name="submit" value="Add text">
</form>


<?php
if (isset($_POST['submit'])){
    $f = fopen("textfile.txt", "a+");
$input = "$_POST[text]\n";
fwrite($f, $input);
}
?>

</body>

</html>
looooooooooool
looooooooooool
looooooooooool
looooooooooool

对我有用,如果这样做了,请喜欢我的答案!

用户不必这样做,用户不会知道,因为他们有点新手,它会产生2个空格,如line1:djdj line3:badjdj..如果你理解了,我只需要1个空格Hanks Tredge你的传奇,如果可以,我会代表你,但由于事实上,我是一个新用户,你现在能代表我的帖子吗?你有足够的代表我也投票了。谢谢。请重复我的任何问题,我将发布