这是搜索栏的 php 代码
家
html、body、div、span、applet、object、iframe、h1、h2、h3、h4、h5、h6、p、blockquote、pre、a、abbr、首字母缩略词、地址、大、引用、代码、del、dfn、 em,字体,img,ins,kbd,q,s,samp,小,罢工,强,sub,sup,tt,var,dl,dt,dd,ol,ul,li,字段集,形式,标签,输入,文本区域,字段集,图例,表格,标题,tbody,tfoot,thead,tr,th,td { margin:0;填充:0;边界:0;大纲:0; }
$keyword=trim($_POST["keyword"]);
//check if the keyword is empty
if($keyword==""){
echo"no keywords";
exit;
}
//With above, you can give hints to your users when they forget to enter a keyword. Now let's go through all the files or articles in your website.
function listFiles($dir){
$handle=opendir($dir);
while(false!==($file=readdir($handle))){
if($file!="."&&$file!=".."){
//if it is a directory, then continue
if(is_dir("$dir/$file")){
listFiles("$dir/$file");
}
else{
//process the searching here with the following PHP script
}
}
}
}
//The following scripts read, process files and check whether the files contain $keyword. If $keyword is found in the file, the file address will be saved in an array-type variable.
function listFiles($dir,$keyword,&$array){
$handle=opendir($dir);
while(false!==($file=readdir($handle))){
if($file!="."&&$file!=".."){
if(is_dir("$dir/$file")){
listFiles("$dir/$file",$keyword,$array);
}
else{
//read file
$data=fread(fopen("$dir/$file","r"),filesize("$dir/$file"));
//avoid search search.php itself
if($file!="search.php"){
//contain keyword?
if(eregi("$keyword",$data)){
if(eregi("(.+)",$data,$m)){
$title=$m["1"];
}
else{
$title="no title";
}
$array[]="$dir/$file $title";
}
}
}
}
}
}
//define array $array
$array=array();
//execute function
listFiles(".","php",$array);
//echo/print search results
foreach($array as $value){
list($filedir,$title)=split("[ ]",$value,"2");
echo "$value"."
\n";
}
?>
hello
</body>
</html>