Я пытаюсь сохранить промежуточный итог всех ответов на форму, которую я написал, но у меня возникают проблемы с ее составлением, чтобы каждый ответ занял новую строку.У меня есть код ниже.Я просто хочу, чтобы его было легче читать, потому что сейчас происходит то, что все ответы, собранные вместе, хотели бы, чтобы каждый из них был на новой строке.Я попробовал несколько вещей и прокомментировал их в коде, и каков был результат.Заранее спасибо.
<?php
if (isset($_POST['sometext']))
{
$myFile = "testFile.txt";
$thetext=$_POST['sometext'] ;//added + "\n" here but all response turned to 0
writemyfile($myFile,$thetext,"a");
} else
{
$thetext="Enter text here";
}
function readmyfile($thefile)
{
$file = fopen($thefile, "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
}
function writemyfile($thefilename,$data,$mode)
{
$myfile=fopen($thefilename,$mode);
fwrite($myfile, $data); // added + "\n" here and responses turned 0
fclose($myfile);
}
?>
<html>
<head>
<title> Zain's Test Site</title></head>
<body>
<form method="post" action="<?php echo $php_self ?>">
<input type="text" name="sometext" value="<?php echo $thetext ?>" >
<input type="submit" name="Submit" value="Click this button">
</form>
<?php readmyfile("testFile.txt"); ?>
</body>