//===================================================================================
// site-search.php = Site Search Script - V1.3 (c) TGH May 2003
//-----------------------------------------------------------------------------------
// This fine script is offered as CONTRIBUTION-WARE:
// - For personal use, send me an email and let me know how you get on.
// - For commercial use, make a donation - the amount is up to you.
//--------------------------------------------------------------------------------------------
// To contribute to The Webmaster's Bureau, or pay for commercial usage of this script see:
// http://web-bureau.com/contribute.php
//============================================================================================
//-------------------------------------------------------------------
// Function: search_dir() - goes thru all files in a directory.
// If files - they're searched for the search term. If directories
// they're searched with this function - it's RECURSIVE!
//-------------------------------------------------------------------
function search_dir () {
global $cur_path, $dir_depth, $matches;
if ($matches > 100) { return; }
//----------------------------------------------------------
// create a string $s_dir containing the full current path.
//----------------------------------------------------------
$s_dir="";
for ($c=0; $c<=$dir_depth; $c++) { $s_dir .= $cur_path[$c]; }
//--------------------------------------------------------------------
// Open the directory, and read all the files from it one by one...
//--------------------------------------------------------------------
$dhandle=opendir("$s_dir");
while ($file = readdir($dhandle)) {
//-------------------------------------------------
// Ignore the 'this' and 'parent' directory items
//-------------------------------------------------
if (($file!=".") && ($file!="..")) {
//-------------------------------------------------------------------------
// if the file is a regular file - check it for the search text.
// Only check files with a .php extension - this is all there is on WB!
//-------------------------------------------------------------------------
if (is_file($s_dir.$file)) {
$file_ext = substr($file, strlen($file)-3, 3);
if ($file_ext == "htm") { search_file($s_dir.$file); }
}
//----------------------------------------------------------------------------------------
// if the file is a directory - add it to the current_path and call this function again.
//----------------------------------------------------------------------------------------
elseif (is_dir($file)) {
$cur_path[++$dir_depth] = ($file."/");
search_dir();
$dir_depth--;
}
}
}
} // End of function.
//----------------------------------------------------------------
// Function: search_file() - searches a file for the search term
//----------------------------------------------------------------
function search_file ($file) {
global $search_term, $results, $r_text, $r_title, $matches;
//----------------------------------------------------------
// create a string $s_dir containing the full current path
//----------------------------------------------------------
$s_dir="";
for ($c=0; $c<=$dir_depth; $c++) { $s_dir .= $cur_path[$c]; }
//-----------------------------------------------------------------------------------------
// Open the file, read it's contents into a variable $f_data. Create a lowercase version so
// the search is case insensitive, then check that for the search term.
//-----------------------------------------------------------------------------------------
$f_size = filesize($file);
$f_handle = fopen($file, "r");
$f_data = fread($f_handle, $f_size);
//--------------------------------------------------------------------
// If the file contains 'SSIGNORE' - Don't Search it. This prevents
// scripts and other non-content files from being searched.
//--------------------------------------------------------------------
if ($text = strstr($f_data, 'SSIGNORE')) { return; }
$f_dlc = strtolower($f_data);
$t_text = "";
$in_tag = 0;
if ($text = strstr($f_dlc, $search_term)) {
$results[$matches] = $file;
//------------------------------------
// Remove any HTML tags from the text
//------------------------------------
for ($c = 0; $c < 200; $c++) {
if (strcmp(substr($text, $c, 3), "<") == 0) { $in_tag=1; }
elseif (strcmp(substr($text, $c, 3), ">") == 0) { $in_tag=0; }
elseif ($in_tag == 0) { $t_text .= substr($text, $c, 1); }
}
$r_text [$matches] = "...". $t_text. "...";
$t_start = strpos ($f_dlc, "
") + 7;
$t_end = strpos ($f_dlc, "");
$r_title[$matches++] = substr($f_data, $t_start, $t_end-$t_start);
}
fclose($f_handle);
} // End of function.
?>
Search |
|
You
may search our web site for all documents containing matching
words or patterns.
|
//----------------------------------------------------
// Initial directory depth = 0 - root directory.
// Current path is stored in an array of directories
//----------------------------------------------------
$dir_depth=0;
$matches=0;
$cur_path = array("./");
$results = array("");
$r_text = array("");
$r_title = array("");
//--------------------------------------------------------------------------------
// Initialise the match count to 0. Ensure the search term is all lower case...
//--------------------------------------------------------------------------------
$search_term=strtolower($search_term);
//---------------------
// Start the search...
//---------------------
if (strcmp($search_term, "")!=0) { search_dir(); }
//---------------------
// Show the results...
//---------------------
$c="#FFFFF8";
for ($a=0; $a<$matches; $a++) {
if ($c=="#FFFFF8") {$c="#F8F8F8";} else {$c="#FFFFF8";}
echo " | ";
echo "$r_title[$a]";
}
echo " | $matches Matches.
";
?>
|