PHP把文本文档的内容按行输出来以后,如何按下图的形式显示出来
程序员文章站
2024-02-03 18:54:28
...
PHP把文本文档的内容按行输出来以后,怎么按下图的形式显示出来。
------解决思路----------------------
form.php
$path = 'D:\wamp\www\a.txt';
$f = fopen($path, "r");
echo "用户名"." " ."密码"." 操作
";
while(!feof($f))
{
if (!feof($f)){
$buffer = fgets($f, 4096);
$arr = explode("
------解决思路----------------------
",$buffer);
if(count($arr) > 1){
echo $arr[0]." " . $arr[1]." 删除
";
}
}
}
fclose($f);
?>
form-action.php
//写入文本
$myfile = fopen("newfile.txt", "a+") or die("Unable to open file!");
$username=@$_POST[username];
fwrite($myfile, $username);
$password=@$_POST[password]."
";
fwrite($myfile, $password);
//读取文件
$myfile = fopen("newfile.txt", "r") or die("Unable to open file!");
// 输出单行直到 end-of-file
while(!feof($myfile)) {
echo fgets($myfile) . "
";
}
fclose($myfile);
?>
用户名 | 密码 | |
删除 |
------解决思路----------------------
form.php
$path = 'D:\wamp\www\a.txt';
$f = fopen($path, "r");
echo "用户名"." " ."密码"." 操作
";
while(!feof($f))
{
if (!feof($f)){
$buffer = fgets($f, 4096);
$arr = explode("
------解决思路----------------------
",$buffer);
if(count($arr) > 1){
echo $arr[0]." " . $arr[1]." 删除
";
}
}
}
fclose($f);
?>
form-action.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 删除
相关文章
相关视频