Ccterran (original) Author: iwind friends made a website with dreamweaver, there is no dynamic content, just some personal rare articles, personal content first and so on. Now there are a lot of content. I want to help him build a search engine. To be honest, this
Ccterran (original)
Author: iwind
My friend used dreamweaver to build a website with no dynamic content. it was just some articles that I had to hide, my preference, and so on. Now there are a lot of content. I want to help him build a search engine. To be honest, this is a title that is not difficult, so I made it easily. Now I have seen some people in other forums who want to do this, so I want to talk about this knowledge and understand the methods.
Before writing a program, think of a good idea. The following is my idea. maybe someone has a better idea, but note that this is just a method Title: traverse all the file shards, read the content, and search for key words, if it matches, it is put into an array; then read the array. Before implementing these steps, I assume that all your web pages are on a scale, that is, there is a title (), There are ( If you use dreamweaver or frontpage, they exist unless you intentionally delete them. Next let's step by step and improve the search engine in the project.
1. design search forms
Create a search.htm file under the root directory of the website. The content is as follows:
Search form
2. search programs
Create a search. php file under the root directory to process the data transmitted from the search.htm form. the content is as follows:
// Obtain key words for search
= Trim ();
// Check whether it is empty
If (= ""){
Echo "the keyword you want to search for cannot be blank ";
Exit; // end the program
}
?>
In this way, if the keyword entered by the visitor is empty, a prompt can be prompted. The following shows how to traverse all objects.
We can use the progressive method to traverse all files. we can use the opendir, readdir, and PHP Directory functions. We now use the former.
// Function for traversing all objects
Function listFiles (){
= Opendir ();
While (false! ==( = Readdir ())){
If (! = '.'&&! = '..'){
// Continuous search for directories
If (is_dir ('/')){
ListFiles ('/');
}
Else {
// Process it here
}
}
}
}
?>
In the red text, we can read and process the searched files. the following describes how to read the file content and check whether the content contains any key words. if the content contains any key words, assign the file address to an array.