[PHP] 纯文本查看 复制代码 <?php
$filename = 'text.txt';
$searchKeyword = isset($_GET['search']) ? trim($_GET['search']) : '';
if (file_exists($filename) && filesize($filename) > 0) {
$str = file_get_contents($filename);
$userinfo = unserialize($str);
// 根据搜索关键词过滤数据
if (!empty($searchKeyword)) {
$filteredUserinfo = [];
foreach ($userinfo as $key => $val) {
// 检查用户姓名、标题、内容是否包含关键词,只要有一项包含就保留
if (stripos($val['username'], $searchKeyword) !== false || stripos($val['title'], $searchKeyword) !== false || stripos($val['content'], $searchKeyword) !== false) {
$filteredUserinfo[$key] = $val;
}
}
$userinfo = $filteredUserinfo;
}
} else {
$userinfo = [];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>查看页面</title>
</head>
<body>
<h3 style="text-align: center;">列表页面-<a href="index.php">添加页面</a></h3>
<!-- 搜索框 -->
<form action="" method="get" style="text-align: center; margin: 20px 0;">
<input type="text" name="search" placeholder="输入关键词搜索" value="<?php echo htmlspecialchars($searchKeyword); ?>" />
<input type="submit" value="搜索" />
</form>
<table style="margin: 0 auto;" border="1" width="60%" align="center" cellpadding="5" cellspacing="0" bgcolor="">
<tr style="text-align: center;" bgcolor="E1E1E1">
<td>序列</td>
<td>姓名</td>
<td>标题</td>
<td>内容</td>
<td>TIME</td>
<td>类型</td>
<td>操作</td>
</tr>
<?php foreach ($userinfo as $key => $val) { ?>
<tr style="text-align: center;">
<td><?php echo $key; ?></td>
<td><?php echo htmlspecialchars($val['username']); ?></td>
<td><?php echo htmlspecialchars($val['title']); ?></td>
<td><?php echo htmlspecialchars($val['content']); ?></td>
<td><?php echo $val['time']; ?></td>
<td><img width="30" height="20" src="img/<?php echo $val['dengj']; ?>" alt=""/></td>
<form action="del.php" method="get">
<input type="hidden" name="Linenumber" value="<?php echo $key; ?>" />
<td colspan="1"><input type="submit" value="删除" /></td>
</form>
</tr>
<?php } ?>
</table>
</body>
</html>
|