我有一个代码当用户键入一个句子并按下添加文本按钮然后文本被发送到一个文件.
这是代码
<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>
Run Code Online (Sandbox Code Playgroud)
它工作正常.有一个问题.
我将用一个例子来展示它.
User1:Oo我可以在这里上传我的家具,好吧就是进入furnidata T(User1的furnidata(他想要添加的文本)被发送到文件..)(它的工作原理)
现在user2出现了
User2:轮到我添加furni数据(与user1相同,它上传到文件并正常工作
但
这就是代码的样子
user1furnidatatatatblahblahblahendofdatauser2furnidatablahblahblahendofdata
这就是我想要它的样子
user1furnidatatatatblahblahblahendofdata …