叁柒設計 三七设计 Three seven design 我的学习与分享
详细信息
来自:关键字:

PHP源码学习:站内搜索HTML版

  December 21th,2008 22:39:58   Category : PHP+Mysql
 Click (504)

<?php 
//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, $msg, $newpath, $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", $msg, $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>"; 

?>

[ 资讯评论 ]
暂时没有任何评论!
[ 提交评论 ]
请选择表情
  • 昵称:
  • *
  • 验证码:
  • *点击更换验证码
  • 尚能输入个字符
申明:本网站部分分享内容来自网络,如有侵权请及时与我联系,谢谢,另网友评论仅代表个人观点,与本站立场无关,如果在评论中发表违反我国任何法律的,请即时与我们联系(QQ:77132915),我们将立即予以删除. [ 注:提交评论后,通过审核后方能在网站上显示!]