|
|
|
<?php
//Sitesearch v1.1 - Sheridan Saint-Michel
//Begin Environment Variables. You need to set these!//
//List of directories to be included in the search.
//Usage "path" => "url" (path to directory and URL which corresponds to directory)
//remember to include the trailing / on the URL
$directories = array(
"/home/mysite/HTML" => "http://www.mysite.com/",
"/home/mysite/HTML/sales" => "http://www.mysite.com/sales/",
"/home/mysite/HTML/products" => "http://www.mysite.com/products/"
);
//End Environment Variables//
Function Keyword_Check($filenames,$keywords)
{
for($i = 0; $i < count($filenames); $i++)
{
$filename = $filenames[$i];
$match = 0;
$fd = fopen($filename, "r");
$contents = fread($fd, filesize ($filename));
fclose($fd);
//Remove HTML Tags before searching
$search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
"'<[\/\!]*?[^<>]*?>'si", // Strip out html tags
"'([\r\n])[\s]+'", // Strip out white space
"'&(quot|#34);'i", // Replace html entities
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(\d+);'e"); // evaluate as php
$replace = array ("",
" ",
"\\1",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\\1)");
$contents = preg_replace ($search, $replace, $contents);
$contents = preg_replace ("/\W/", " ", $contents);
$contents = preg_replace ("/\s+/", " ", $contents);
//Seperate Each Word into an Array Element and Compare to Keywords
$contents = explode(" ", $contents);
$j = 0;
for($j = 0; $j < count($keywords); $j++)
{
for($k = 0; $k < count($contents); $k++)
{
//compare contents with each keyword
if (!strcasecmp ($contents[$k], $keywords[$j]))
{
$match++;
break;
}
}
}
if ($match == count($keywords) )
$retVal[count($retVal)] = $filename;
}
return $retVal;
}
function Get_Filenames($directory)
{
//Load Directory Into Array
$handle=opendir($directory);
while ($file = readdir($handle))
{
if ($file != "." && $file != "..")
$retVal[count($retVal)] = $file;
}
//Clean up and sort
closedir($handle);
sort($retVal);
return $retVal;
}
if ( isset($keyword) )
{
$keywords = explode(" ", $keyword);
$pages = array();
while (list ($key, $val) = each ($directories))
{
$directory = $key;
chdir($directory) or die("Directory $directory Not found");
$filenames = Get_Filenames($directory);
$found = Keyword_Check($filenames,$keywords);
//add any pages with keywords in current directory to array
for($i = 0;$i < count($found); $i++)
{
$add = "$val$found[$i]";
$pages[count($pages)] = $add;
}
}
?>
<HTML>
<Head>
<Title>Website Search</Title>
</Head>
<?php } ?>
<Body>
<Form Action=search.php>
<Input Type=Text Name=keyword Value="$keyword";>
<Input Type=Submit Value=Search>
<Input Type=Reset Value="New Search">
<?php
if ( isset($keyword) )
{
echo "<HR>\n";
echo "<Font Color=Blue>$numfound pages matching your query were found</Font>";
echo "<HR>";
for ($i = 0; $i < count($pages); $i++)
echo "<A HREF=\"$pages[$i]\">$pages[$i]</A><BR>";
}
?>
</Form>
</Body>
</HTML> |
|
| How to build a search query for any N number of words in a search string Categories : PHP, Regexps, Search Engines, Search | | | Searches through a local INN server's discussions Categories : Search, Complete Programs, PHP | | | PageRank Display Categories : Search Engines, HTML and PHP, PHP | | | http://phpMySearch.web4.hm - The phpMySearch search engine system is a completeworld wide web indexing and searching system for a small domain or intranet. Categories : Search Engines, PHP, Databases, MySQL | | | Boolean Keyword Interpreter Categories : PHP, Algorithms, Search Engines | | | UDMSearch - a free search engine, indexing system. Categories : Search Engines, Linux, PHP, MySQL, ODBC | | | free, search engine, indexing, system, information, web,
ftp, http, free, software, cgi, php, MySQL, database, php3,
FreeBSD, Linux, Unix, UdmSearch Categories : MySQL, Complete Programs, PHP, Databases, Search | | | SubmitForce URL power submitter (searchengine submission class) Categories : PHP, Search Engines, URLs, PHP Classes | | | Add Boolean Logic Functions to Database Queries Easily. A
function to write a WHERE clause dynamically to search a
database from a search form.
Categories : MySQL, PHP, Search | | | Extended Get File List Function Categories : PHP, Filesystem, Search, Directories | | | Client classes for Dictionary servers UPDATED: 2000-06-06 Categories : Network, Search, Complete Programs, PHP Classes, PHP | | | whois domain name lookup dns url Categories : PHP, Search, Network | | | Search for files Categories : PHP, Filesystem, Search | | | Dynamic pages with no "?" Categories : PHP, Search Engines | | | Search and Replace Text : Searches Files for Specified Text and Replaces It by a Given Text Categories : PHP, PHP Classes, Search, Filesystem | |
| | | | Dave Carrera wrote : 591
I like the simplisity of this script BUT... is the value="$keyword" in the form area a typo as it displays $keyword in the search box on each reload...should it be name="$keyword" ???? good and cool script
| | | | Sheridan Saint-Michel wrote : 592
You`re right that was an oversight =) Change
<Input Type=Text Name=keyword Value="$keyword";>
to read
<?php echo "<Input Type=Text Name=keyword Value=\"$keyword\">"; ?>
and it should work right =)
| | | | Bill Williams wrote : 640
Excellent script! But there are some more minor problems:
1) If you search for a "space", then it lists all files and sub-directories of the root! Right after Get_Filenames(), Change this line:
if ( isset($keyword)) {
to:
if ( isset($keyword) && strlen($keyword) > 0) {
2) You never use the variable $numfound! I set it to 0 at the top of the script, then added this after the form:
if ($numfound > 0) {
echo "<font color=\"#0000cc\">$numfound Page(s) matching your query were found:</font>";
echo "<hr noshade size=\"1\" color=\"#dddddd\">\n";
} else {
echo "<font color=\"#cc0000\">No Pages matching your query were found. Please search again.</font>";
}
I also added:
$numfound += 1;
in the loop after the comment "//add any pages with keywords in current directory to array"
3) And finally, you include sub-directores in your results, a HUGE security hole, since I don`t want visitors to know where my admin or includes directories reside! Change this:
if ($file != "." && $file != ".." && !is_dir($file)) { $retVal[count($retVal)] = $file; }
in the conditional in Get_Filenames()
| | | | Sheridan Saint-Michel wrote : 642
I just looked over it again and discovered that a line somehow got missed when I copied it to the site. In the script I am running I have the line
$numfound = count($pages);
Here
if ( isset($keyword) )
{
$keywords = explode(" ", $keyword);
$pages = array();
while (list ($key, $val) = each ($directories))
{
$directory = $key;
chdir($directory) or die("Directory $directory Not found");
$filenames = Get_Filenames($directory);
$found = Keyword_Check($filenames,$keywords);
//add any pages with keywords in current directory to array
for($i = 0;$i < count($found); $i++)
{
$add = "$val$found[$i]";
$pages[count($pages)] = $add;
}
}
$numfound = count($pages);
?>
Not sure how I managed to lose a line of code.... Copy and Paste has never failed me before =)
Also thanks for the comment concerning the space =)
| | | | Sheridan Saint-Michel wrote : 643
I also added the line you suggested concerning the subdirectories. Thanks a lot, I appreciate it =)
| | | | mark Pau wrote : 657
Very nice program...... But something want to know!
How to change the search result only ".html" and ".htm" files ?
| | | | Sheridan Saint-Michel wrote : 659
Any changes to the types of files returned would be accomplished by changing the line
if ($file != "." && $file != "..")
in the Get_Filenames Function.
So to only return .htm and .html you would change that line to read something like
if(substr($text[$j], -4, 4) == ".htm" || substr($text[$j], -5, 5) == ".html")
Hope that helps
Sheridan
| | | | Heinz Ernst wrote : 689
How do I manage to have the script working on a windows-system? I have Apache installed as standalone on a NT4-Machine. I appreciate helpful hints. Thanks a lot.
Heinz
| | | | john culby wrote : 713
i want to search for a string such as word-word-word so i guess my question is how do i strip out a dash
thanks
| | | | Christopher Leon wrote : 717
I am running this on windows2000 server, and I can get it to run if I set it to look in one directory, but when I open it up to a directory that has many subdirs, I get this message:
Warning: fopen("10.16.01","r") - Permission denied in L:\lvweb\search.php on line 24
it will also say it for the directory that I was originally searching in, and I know that it has read rights
thanks
| | | | kenneth saandvig wrote : 779
I am having problems with this script... When uploading it and going to the page, it produces this output:
Parse error: parse error in /home/httpd/mywebsite/www/search.php on line 7
What a`m I doing wrong????
| | | | kenneth saandvig wrote : 780
I was a little quick before... I just had to copy the "plain text". sorry =)
This is a VERY nice script
Thanx=)
| | | | java maniacs wrote : 787
hmm... I get this:
Warning: fopen(".search.phtml.swp", "r") - Permission denied in /home/javamaniacs/www/dev/search.phtml on line 24
Warning: Supplied argument is not a valid File-Handle resource in /home/javamaniacs/www/dev/search.phtml on line 25
Warning: Supplied argument is not a valid File-Handle resource in /home/javamaniacs/www/dev/search.phtml on line 26
| | | | java maniacs wrote : 788
D`oh! Never mind. Had the file open in vi and was trying to search a swap file! ....
| | | | Sheridan Saint-Michel wrote : 789
Version 1.2 lets you filter out files from the search, so you shouldn`t run into this. I`ll post a copy here in the next few days, or you can view it at my homepage:
http://www.onlychildclub.com/Lysander/Code/
| | | | Jackson Lim wrote : 799
err... can anyone explain to me how to use the codes?
I would really appreciate it.
Thank you
(just started learning, a bit confused)
| | | | gili sabach wrote :1024
Hello!
Great script, but I found that he does`nt support active search in my own language.
for example: if I`ll type word search in hebrew language he won`t find nothing, can I do something to fix this?
thank`s and again nice and really helping script.
soory about my english and have a nice day!
waiting for answer, Gili.
| |
|
|
|