如何在两个$ _POST函数之间插入空格

时间:2013-10-03 01:19:13

标签: php textbox space

我有以下代码:

<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”为

bluebuffalo

我怎样才能阅读

蓝色水牛

谢谢!

2 个答案:

答案 0 :(得分:2)

这可以解决问题:

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

答案 1 :(得分: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>