ネパール.com 検索
if(safe_request("s") != ""){ require_once 'File/Find.php'; $dirpath = "/home/keigo/sites/nepal.thi.jp"; $files = File_Find::search ("/.*\.html?$/", $dirpath, "perl"); // 無視するファイル $files = preg_grep ("@/gallery2/@", $files, PREG_GREP_INVERT); $files = preg_grep ("@/404.html$@", $files, PREG_GREP_INVERT); // dpr($files); $data = array(); foreach( $files as $file ){ $contents = file_get_contents("$file"); if($s_mode == "AND"){ $match = true; // AND 検索なので$match = true にしておき、マッチしなかったら$match = false foreach($s_words as $s_word){ $s_word_preg = preg_quote($s_word); if(! preg_match("/$s_word_preg/i", $contents)){ $match = false; break; } } if($match){ preg_match("@"; $title = strip_tags($matches[1]); $linkpath = preg_replace("@^$dirpath@", "",$file); $data[] = "$title"; } } else if ($s_mode == "OR"){ // OR 検索なのでひとつでも引っかかればOK foreach($s_words as $s_word){ $s_word_preg = preg_quote($s_word); if(preg_match("/$s_word_preg/i", $contents)){ preg_match("@
"; $title = strip_tags($matches[1]); $linkpath = preg_replace("@^$dirpath@", "",$file); $data[] = "$title"; break; } } } } $s_word_html = strip_tags(implode(" $s_mode ", $s_words)); $cnt = count($data); echo "$s_word_html の検索結果 ($cnt 件)
"; echo ""; if($data){ foreach($data as $r ){ echo $r . "
"; } } else { echo "検索キーワードにマッチするページはありません。"; } } else { echo "検索キーワードを入力してください。"; } ?>
