0

我有以下代码:

<html>
<head>
<title>Write to a text file</title>
</head>
<body>
Add your text
<form action="" method='post'>
<input name='textblock'></input>
<input name='otherblock'></input>
<input type='submit' value='Add text'>

</form>

<?php

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

// Write text
fwrite($f, $_POST["textblock"] . $_POST["otherblock"] . "\r\n");

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

$filecontents = file_get_contents("texties.txt");
print nl2br($filecontents);
?>

</body> 
</html>

这会产生用户在文本框中输入的任何内容,例如“blue”和“buffalo”作为

蓝水牛

我怎样才能让它阅读

蓝水牛

谢谢!

4

2 回答 2

2

这可以解决问题:

fwrite($f, $_POST["textblock"]." ". $_POST["otherblock"] . "\r\n");
于 2013-10-03T01:21:33.937 回答
0

当你看到这个时你会踢自己,但它很简单:

<html>
<head>
<title>Write to a text file</title>
</head>
<body>
Add your text
<form action="" method='post'>
<input name='textblock'></input>
<input name='otherblock'></input>
<input type='submit' value='Add text'>

</form>

<?php

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

// Write text
fwrite($f, $_POST["textblock"] . " " . $_POST["otherblock"] . "\r\n");

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

$filecontents = file_get_contents("texties.txt");
print nl2br($filecontents);
?>

</body> 
</html>
于 2013-10-03T01:26:00.727 回答