求一段PHP搜索本地文件代码

来源:百度知道 编辑:UC知道 时间:2024/07/02 20:42:45
search.php
txt/

txt文件夹都是古诗词

静夜思.txt
月下独酌.txt
行路难.txt
...

要写search.php代码.
把txt目录所有文件转成一个数组。
然后在数组里对比$_GET['kw'] 关键字。
关键字有可能是 静夜思 或月下独酌 或者其他。
匹配和关键字相同的文件名然后输出。
如果没有匹配的文件输出 "没有这个文件".
越简单越好。。。
谢谢……

在php 5.2 中文windows xp通过,如果显示乱码,请在php.ini中设置
default_charset = "gbk"

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
</head>
<body>
<form method="POST">
<table>
<tr>
<td>keyword:</td><td><input type="text" size="20" value="<?php echo isset($_REQUEST["kw"])?$_REQUEST["kw"]:""; ?>" name="kw"></td><td><input type="submit" name="go!" value="submit"></td>
</tr>

</table>
</form>

<?php
echo "<pre>";
if(isset($_REQUEST["kw"]))
{
$targetdir = "./txt";

$dir=dir($targetdir);
//rename usage
while($entry=$dir->read())
{
if(