
<?php
//写入文本
$myfile = fopen("newfile.txt", "a+") or die("Unable to open file!");
$username=@$_POST[username];
fwrite($myfile, $username);
$password=@$_POST[password]."<br>";
fwrite($myfile, $password);
//读取文件
$myfile = fopen("newfile.txt", "r") or die("Unable to open file!");
// 输出单行直到 end-of-file
while(!feof($myfile)) {
echo fgets($myfile) . "<br>";
}
fclose($myfile);
?>
<html>
<header>
</header>
<body>
<form action="index.php" method="post">
用户名:<input type="text" name="username"/><br><br>
密码:<input type="text" name="password" /><br><br>
<input type="submit" value="提交"/>
</form>
<table border="0">
<tr><td>用户名</td><td>密码</td></tr>
<tr>
<td><?php echo $username ?></td>
<td><?php echo $password ?></td>
<td>删除</td>
</tr>
</table>
</body>
</html>
------解决思路----------------------
form.php
<html>
<head>
<meta charset="utf-8"/>
<title></title>
</head>
<body>
<form name="form" action="form-action.php" method="post">
<input name="username" type="text" />
<input name="password" type="text"/>
<input type="submit" name="submit" value="提交"/>
</form>
<?php
$path = 'D:\wamp\www\a.txt';
$f = fopen($path, "r");
echo "用户名"." " ."密码"." 操作<br/>";
while(!feof($f))
{
if (!feof($f)){
$buffer = fgets($f, 4096);
$arr = explode("
------解决思路----------------------
",$buffer);
if(count($arr) > 1){
echo $arr[0]." " . $arr[1]." 删除<br/>";
}
}
}
fclose($f);
?>
</body>
</html>
form-action.php
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$path = 'D:\wamp\www\a.txt';
$fp = fopen($path,"a");
fwrite($fp,$username."
------解决思路----------------------
".$password."\r\n");
fclose($fp);
header("Location:form.php");
?>
用户名 密码 操作
11 22 删除
33 44 删除
55 66 删除
ss dd 删除
s sss 删除