0
我试过几个不同的连接来自文本框输入的不同变化,但没有一个工作。任何人都可以通过向我展示如何将所有这些内容连接在一条线上(背对背)?在php代码中连接
HTML
<form method="post" action="sample.php">
<p>My Information
<br />City State <input type="text" name="item1" size="30">
<br />State Name <input type="text" name="item2" size="30">
<br />County Name <input type="text" name="item3" size="30">
</p>
<input type="submit" value="Submit Information">
</form>
PHP
<?php
print "<h4>Geographic Location<b/h4>>";
$filename = 'data/'.'sample.txt';
$fp = fopen($filename, 'w'); //w opens the file for writing
$cntr = 1;
while(true)
{
$item_name = 'item'.$cntr;
$item = $_POST[$item_name];
if (empty($item))
{
break;
}
$cntr++;
print "Item: ".$item."<br />";
$output_line = $item."\n";
fwrite($fp, $output_line);
}
'$ output_line。= $ item。“”;'我假设你在每个 –
@Dagon之间有一个空格不,这不是必要的。他将每行写入循环内的文件,因此他不需要连接它们。 – Barmar
哦,真的......尽管他应该把文件写在循环外 –