通过从txt文件中读取名称,使用php标记存在和不存在
我制作了一个php文件,通过读取“attention.txt”文件中给出的名称来标记出席和缺席。我该怎么做? 它给了我错误的答案。 我已经在标签中应用了php通过从txt文件中读取名称,使用php标记存在和不存在,php,html,Php,Html,我制作了一个php文件,通过读取“attention.txt”文件中给出的名称来标记出席和缺席。我该怎么做? 它给了我错误的答案。 我已经在标签中应用了php <html> <head> <style> table,th,td { border:1px solid black; border-collapse:collapse; } th,td { padding:5px; } </style> </head> <body &
<html>
<head>
<style>
table,th,td
{
border:1px solid black;
border-collapse:collapse;
}
th,td
{
padding:5px;
}
</style>
</head>
<body >
<div id="container" style="width:1250px">
<div id="header" style="background-color:#FFA500;">
<h1 style="margin-bottom:0;text-align:center;">WEBKIOSK ATTENDANCE</h1></div>
<div id="menu" style="background-color:#FFD700;height:500px;width:250px;float:left;">
<br>
<b>Teacher's name</b><br><br>
<b>class timing</b><br><br>
<b>Lecture/tutorial</b>
</div>
<div id="content" style="background-color:#CCCCFF;height:500px;width:1000px;float:left;text-align:right;">
<img src="logo.jpg"width="145" height="175">
<table align=center style="width:300px;">
<tr>
<th style="color:#FF0000;"><i>S.NO</i></th>
<th style="color:#FF0000;"><i>ENROLLMENT NO.</i></th>
<th style="color:#FF0000;"><i>NAME</i></th>
<th style="color:#FF0000;"><i>PRESENT/ABSENT</i></th>
</tr>
<tr>
<tr>
<td>1.</td>
<td>11102213</td>
<td>Divyansha</td>
<td><form>
<input <?php $myfile = fopen("attendance.txt", "r") or die("Unable to open file!");if(strcmp("Divyansha",fgets($myfile))) echo'checked="checked"';?> type="radio" name="attendance1" value="present">
<input <?php $myfile = fopen("attendance.txt", "r") or die("Unable to open file!"); if((strcmp("Divyansha",fgets($myfile))==-1)) echo'checked="checked"';?> type="radio" name="attendance1" value="present">
</form></td>
</tr>
<tr>
<td>2.</td>
<td>11102310</td>
<td>Romil</td>
<td> <form>
<input <?php $myfile = fopen("attendance.txt", "r") or die("Unable to open file!");if(strcmp("Romil",fgets($myfile))) echo'checked="checked"';?> type="radio" name="attendance2" value="present">
<input <?php $myfile = fopen("attendance.txt", "r") or die("Unable to open file!");if((strcmp("Romil",fgets($myfile))==-1)) echo'checked="checked"';?> type="radio" name="attendance2" value="present">
</form></td>
</tr>
<tr>
<td>3.</td>
<td>11103566</td>
<td>Shikher</td>
<td><form>
<input <?php $myfile = fopen("attendance.txt", "r") or die("Unable to open file!");if(strcmp("Shikher",fgets($myfile))) echo'checked="checked"';?> type="radio" name="attendance1" value="present">
<input <?php $myfile = fopen("attendance.txt", "r") or die("Unable to open file!"); if((strcmp("Shikher",fgets($myfile))==-1)) echo'checked="checked"';?> type="radio" name="attendance1" value="present">
</form></td>
</tr>
<tr>
<td>4.</td>
<td>11102210</td>
<td>Dhruv</td>
<td><form>
<input <?php $myfile = fopen("attendance.txt", "r") or die("Unable to open file!");if(strcmp("Dhruv",fgets($myfile))) echo'checked="checked"';?> type="radio" name="attendance1" value="present">
<input <?php $myfile = fopen("attendance.txt", "r") or die("Unable to open file!"); if((strcmp("Dhruv",fgets($myfile))==-1)) echo'checked="checked"';?> type="radio" name="attendance1" value="present">
</form></td>
</tr>
</table></div>
<div id="footer" style="background-color:#FFA500;clear:both;text-align:center;">
Jaypee Instiute Of Information Technlogy</div>
</div>
</body>
</html>
表,th,td
{
边框:1px纯黑;
边界塌陷:塌陷;
}
th,td
{
填充物:5px;
}
网络信息亭出席率
教师姓名
上课时间
讲座/辅导
序号
注册号。
名称
出席/缺席
1.
11102213
迪文萨
type=“radio”name=“attendance1”value=“present”>
2.
11102310
罗米尔
type=“radio”name=“attendance2”value=“present”>
3.
11103566
什克尔
type=“radio”name=“attendance1”value=“present”>
4.
11102210
杜鲁夫
type=“radio”name=“attendance1”value=“present”>
杰佩信息技术学院
而“Attention.txt”包含:
罗米尔
迪文萨
Shikher您可以读取一次文件并创建一个名称数组,然后根据该数组使复选框为true或false
$names = array();
$handle = @fopen("/path/to/attendance.txt", "r");
if ($handle) {
while (!feof($handle)) {
$names[] = fgets($handle);
}
fclose($handle);
}
您还可以使用文件('/path/to/attention.txt')
函数,该函数将返回与文件中的一行对应的数组现在在html中,您可以在数组中使用
<input <?php if(in_array('Divyansha',$names)) echo'checked="checked"'; ?> type="radio" name="attendance1" value="present">
您是否在文件中使用任何分隔符来分隔每个名称?它可以是任何东西(,;。换行符等)是的,我正在使用换行符分隔名称…检查我下面的答案,希望它会有帮助它没有帮助兄弟…它仍然显示所有名称的缺席。。