Home > php教程 > php手册 > 翻出一篇老文章:php文本站内全文检索

翻出一篇老文章:php文本站内全文检索

WBOY
Release: 2016-06-21 09:11:56
Original
1135 people have browsed it

全文检索

/****************************************************   
原作者: uchinaboy    
修改:lingshidao
特点:无需mysql支持;速度快;无需设置路径,放在哪级目录下,就搜索该目录和子目录;可以搜索一切文本类型的文件;显示文件相关内容;关键词自动高亮显示。
修改内容:增加了自动分页和风格设置文件。
搜索框代码(如果放在search.php相同目录下,无需修改):

                         

****************************************************/  
require ("template.php");
echo "

";
echo "检索结果";
echo "


";
if (function_exists("set_time_limit") && !get_cfg_var('safe_mode')){
set_time_limit(600);}
function get_msg($path) {  
global $key, $i;  
$handle = opendir($path);  
while ($filename = readdir($handle)) {  
//echo $path."/".$filename."
";  
$newpath = $path."/".$filename;  
if (is_file($newpath)) {  
$fp = fopen($newpath, "r");  
$msg = fread($fp, filesize($newpath));  
fclose($fp);  
match_show($key, $msg, $newpath, $filename);  
}  
if (is_dir($path."/".$filename) && ($filename != ".") &&  ($filename != "..")) {  
//echo "


".$newpath."


";  
get_msg($path."/".$filename);  
}  
}  
closedir($handle);  
return $i;  
}  

function match_show($key, $msg, $newpath, $filename) {
  global $i;
  $key = chop($key);
  if($key) { $check_type = preg_match("/\.html?$/", $filename);
  if($check_type) {$title = getHtmlTitle($msg);}
    $msg = preg_replace("/
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template