Build a self-site search engine

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.