ホームページ  >  記事  >  バックエンド開発  >  PHPサイト検索

PHPサイト検索

WBOY
WBOYオリジナル
2016-06-23 14:32:152276ブラウズ

search.php ファイル

/*************************************************** *
オリジナル作者: uchinaboy
特徴: mysql のサポートは必要ありません; パスを設定する必要がなく、どのディレクトリに配置されていても、ディレクトリとサブディレクトリが検索されます。コンテンツ、キーワードが自動的に強調表示されます。
変更内容: 自動ページングとスタイル設定ファイルを追加しました。
検索ボックスのコード (別の HTML ファイルとして保存してください。search.php と同じディレクトリに配置する場合は変更する必要はありません):

Method="post" action="search.php">< ;input type=" text" name="key" size=40 value="">
***** ***************************************/
require ("search.inc"); 
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."/".$ファイル名; 
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 "
< ;br>".$newpath."

"; 
get_msg($path."/".$filename); 
}
}
Closedir($handle); 
$i を返します。 
}

function match_show($key, $msg, $newpath, $filename) {
global $ar, $i; 
$key = チョップ($key); 
if($key) { $check_type = preg_match("/.html?$/", $filename); 
if($check_type) {$title = getHtmlTitle($msg);}
$msg = preg_replace("//is", "", $msg); 
$msg = preg_replace("/<[^>]+>/", "", $msg); 
$value = preg_match("/.*$key.*/i", $msg, $res); 
if($value) {

$res[0] = preg_replace("/$key/i", "$key", $res[0]) ; 
$k = $res[0]; 
$k = strrchr($k, " $k = substr($k, 1, 100); 
$k = "$key if($title) {$m = $title;} else {$m = $filename;}
$i++; 
$link = $newpath; 
$ar[] = 「$i.◆$m

」 .$k."

"; 
}
}else {
echo "请输入关键词"; 
終了します。 
}
}

function getHtmlTitle($msg) {

/* Locate where  html ファイル内にあります。 */ <br> $lBound = strpos($msg, '<title>') + 7; //7 は <TITLE> の長さです。 <br> <br> if ($lBound < 1) <br /> return; <br /> <br />       /* 検索場所  html ファイル内にあります。 */
$uBound = strpos($msg, '', $lBound); 

if ($uBound < $lBound)
return; 

/* 以下の狂気を備えた $title から HTML タグと PHP タグを削除します。 */
$title = ereg_replace("[tnr]", '', substr($msg, $lBound, $uBound -
$lBound)); 
$title = trim(strip_tags($title)); 

if (strlen($title) < 1) //空白のタイトルには価値がありません。 
戻る; 

$title を返す; 
}

$i = get_msg("."); 
if (empty($page)) $page=1; 
$maxresult=($page*20); 
$resultcount = count($ar); 
if ($resultcount%20==0) $maxpageno=$resultcount/20; 
else $maxpageno=floor($resultcount/20)+1; 
if ($page>$maxpageno) { $page=$maxpageno; $pagemax=$resultcount-1; $pagemin=max
(0,$result_count-20);}
elseif ($page==1) {$pagemin=0; $pagemax=min($result_count-1,20-1); }
else { $pagemin=min($resultcount-1,20*($page-1)); $pagemax=min($resultcount-
1,$pagemin+20-1); }
$maxresult=min($maxresult,$resultcount); 
echo "

"; 
echo "浩园软件检索结果"; 
echo "


"; 
for ($i=max(0,$maxresult-20); $i<$maxresult; $i++) {
print $ar[$i]; 
}
echo "

"; 
echo " 已经搜索到了 $resultcount 条情報"; 
$nextpage=$page+1; 
$previouspage=$page-1; 
echo " --- [ 搜索下 20
个结果
]"; 
echo " [ 返上 20
个结果
]"; 
終了; 

?> 

search.inc文書

 
 
 
 
 
全文検索 
 
 

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
前の記事:再版 --- php 設定次の記事:再版 --- php 設定