前端之家收集整理的这篇文章主要介绍了
php 站内搜索HTML实现方法,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
对
PHP 站内
搜索HTML版感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!
PHP代码如下:
<?PHP
/**
* PHP 站内搜索HTML版
* @param
* @arrange (512.笔记) jb51.cc
* require("config.inc.PHP");
**/
function get_msg($path) {
global $key,$i;
$handle = opendir($path);
while ($filename = readdir($handle)) {
//echo $path."/".$filename."<br>";
$newpath = $path."/".$filename;
$check_type = preg_match("/\.html?$/",$filename);
if (is_file($newpath) && $check_type) {
$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 "<BR><BR><BR>".$newpath."<BR><BR><BR>";
get_msg($path."/".$filename);
}
}
closedir($handle);
return $i;
}
function match_show($key,$filename) {
global $key,$i; $key = chop($key);
if ($key) {
$msg = preg_replace("/<style>.+<\/style>/is","",$msg);
$msg = str_replace(" ",$msg);
$msg = preg_replace("/<[^>]+>/",$msg);
$value = preg_match("/.*$key.*/i",$res);
if ($value) {
$res[0] = preg_replace("/$key/i","<FONT SIZE=\"2\" COLOR=\"red\">$key</FONT>",$res[0]);
$i++; $link = $newpath;
print "<a href=\"$link\">$filename</a><BR>";
print $res[0]."<BR><br>";
}
}else {
echo "请输入关键词";
exit;
}
}
$i = get_msg(".");
echo "<BR><BR>".$i."<BR><BR><BR>";
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/527925.html