我从Post Array中获取了很多字符串变量,然后将它们连接成一个字符串。我正在尝试将此字符串写入名为singles.txt的文件
出于某种原因,在我的代码中,它只是在写入文件时添加一个空行?我似乎无法找到答案。
<?php
$name = $_POST["name"];
$age = $_POST["age"];
$personality = $_POST["personality"];
$favOS = $_POST["favOS"];
$min = $_POST["min"];
$max = $_POST["max"];
if($_POST['gender'] === 'female'){
$gender = 'F';
}
else if($_POST['gender'] === 'male'){
$gender = 'M';
}
$singlesfile = 'singles.txt';
$singles = file_get_contents($singlesfile);
$personinfo = $name . $gender . $age . $personality . $favOS . $min . $max;
$singles .= $personinfo;
file_put_contents($singlesfile, $singles);
?>
这是我的表格,对不起,如果它看起来很乱,那就复制了怪异 新用户注册:
<label> Name: <input type="text" name="name" size="16" /> <br/>
<label> <strong> Gender: </strong> <input type="radio" name="gender" value="male"
/> </label> Male
<input type="radio" name="gender" value="female" checked = "checked" /> Female
</br>
<label> <strong> Age: </strong> <input type="text" name="age" size="6"
maxlength="2" /> </label> <br/>
<label> <strong> Personality: </strong> <input id="personality" type="text"
name="personality" size="6" maxlength="4" /> <a
href="http://www.humanmetrics.com/cgi-win/JTypes2.asp ."> (Don't know your
personality?) </a> <br/>
<select name="favOS">
<option selected="selected">Windows</option>
<option>OS X</option>
<option>Linux</option>
<option>Android</option>
<option>iOS</option>
</select>
</br>
<label> <strong> Seeking Age: </strong> <input type="text" name="min" size="6"
maxlength="2" placeholder="min" />
<label> to </label>
<input type="text" name="max" size="6" maxlength="2" placeholder="max" /> <br/>
<input type="submit" name="signup" value="Sign Up!"/>