您的位置:首页 > 编程语言

只需几句代码即可完成网页内的搜索的功能

2013-02-27 11:54 351 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="imagetoolbar" content="false" />
<meta name="baidu-site-verification" content="JQiKjfbHRXKGMrk2" />
<meta name="Copyright" content="Copyright www.lunanzuche.com All Rights Reserved." />
<meta name="MSSmartTagsPreventParsing" content="true" />
<meta name="author" content="MR newdomer" />
<title>search results</title>
</head>
<body>
<?PHP
/**
* s即表单提交来的参数
**/
$s = $_GET['s'];
$dir = substr($_SERVER["SCRIPT_FILENAME"],0,-10);//获取网站文件夹
$dir=opendir($dir);//Ŀ¼
while(($file=readdir($dir))!==false){

if($file!=="." && $file!==".." &&strpos($file,".")){
//ȡļ
$c  = file_get_contents($file);
//ƥǷؼ
$s  = $s;
$r  = "/\<title\>(.*)$s(.*)\<\/title\>/i";
if(preg_match($r,$c)){
$list[]=$file;
}

}

}
if(empty($list)){
echo "no result";
}else{
print_r($list);
}
//print_r(count($list));

closedir($dir);

?>

</body>
</html>

此种方式只适用于小的网站,暂时没有分页功能
本文出自 “江南才子” 博客,请务必保留此出处http://cet68.blog.51cto.com/6512168/1141244
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: