Full analysis of PHP search engine development technology, PHP search engine development_PHP tutorial

WBOY
Release: 2016-07-13 10:17:36
Original
983 people have browsed it

Full analysis of search engine technology developed by PHP, search engine developed by PHP

When talking about web search engines, many people will think of Yahoo. Indeed, Yahoo created an era of Internet search. However, the technology Yahoo currently uses to search the web was not originally developed by the company. In August 2000, Yahoo adopted technology from Google, a company founded by Stanford University students. The reason is very simple. Google's search engine can search for the required information faster and more accurately than the technology previously used by Yahoo.

It is probably impossible for us to design and develop a powerful and efficient search engine and database ourselves in a short period of time in terms of technology and funds. However, since Yahoo is using other people’s technology, then we are Can’t we also use other people’s ready-made search engine websites?

 Analysis of programming ideas

We can imagine this: simulate a query, issue a search command in a corresponding format to a search engine website, then return the search results, analyze the HTML code of the results, strip off redundant characters and codes, and finally press the required The format is displayed on our own website pages.

In this way, the key to the problem is that we need to select a search result that has accurate information (so that our search will be more meaningful) and fast (because it takes extra time for us to analyze the search results and display them). A simple (convenient for HTML source code analysis and stripping) search website. Due to the various excellent features of the new generation search engine Google, here we choose it as an example to see how to use PHP to achieve background Google search and front-end personalized display. This process.

Let’s first take a look at the composition of Google’s query commands. Enter the Google website, enter "abcd" in the query bar, click the query button, we can find that the browser's address bar changes to: "http://www.google.com/search?q=abcd&btnG=Google%CB%D1 %CB%F7&hl=zh-CN&lr= ", it can be seen that Google passes query parameters and submits query commands through the get method of the form. We can use the file() function in PHP to simulate this query process.

 Understand the File() function

Syntax: array file(string filename);

 The return value is an array, and all files are read into the array variable. The file here can be local or remote. The remote file must indicate the protocol used. For example: result=file("http://www.google.com/search?q=a ... mp;hl=zh-CN&lr= "), this statement will simulate our query for the word "abcd" on Google process, and transfer the search results back to the array variable result in the form of elements per row. Because the file read here is remote, the protocol name "http://" cannot be missing.

If we want users to enter search characters for any search, we can make an input text box and submit button, and replace the searched character "abcd" above with a variable:

echo '

 ; file://form without parameters, the default submission method is get, submitted to itself

echo '; file://Construct a text input box

echo '; file://Construct a submit query button

echo '

 ;

 if (isset(keywords)) file://After submission, PHP will generate the variable kwywords, which requires the following program to run after submission

 {

 urlencode(keywords); file://URL-encode user input

result=file("http://www.google.com/search?q=". keywords."&btnG=Google%CB%D1%CB%F7&hl=zh-CN&lr=");

File:// performs variable substitution on the query statement and saves the query results in the array variable result

result_string=join(" ", result); file:// Merge the array $result into a string, and paste each array element with a space

 ... file://further processing

 }

 ?﹥

The above program can already query based on user input and synthesize the returned results into a string variable $result_string. Please note that you must use the urlencode() function to URL-encode the user input so that the input Chinese characters, spaces, and other special characters can be queried normally. This also simulates Google's query commands as realistically as possible to ensure the search results are accurate. Correctness.

 Analysis of Google

To make it easier to understand, let’s assume that what we really need is: the title of the search results. URL and introduction, etc. This is a simple and typical requirement. In this way, all we have to do is: remove the header and footer of Google search results, including a Google logo, input box for re-search, search result description, etc., and strip the original HTML from the remaining search result items. Format tag, replace it with the format we want.

To do this, we must carefully analyze the HTML source code of Google search results and find the rules. It is not difficult to find that the text of Google search results is always included in the first

of the source code

Mark and penultimate

between tags, and the penultimate

The tag is followed by the table character, and this combination "

All the following procedures are continued in the "further processing" section of the above procedure.

result_string = strstr( result_string, " ");

File://Get the string after result_string starting from the first one to remove the Google header

Position= strpos( result_string, "The position of the table symbol

result_string= substr(result_string,0, position);//Intercept the string before the first table symbol to remove the footnote

 Application and implementation

Now that we have a useful HTML source code backbone, the remaining question is how to display this content autonomously. Let's analyze these search result entries again and find that each entry is also separated very regularly, that is, each entry is a paragraph. According to this feature, we use the explode() function to cut each entry:

Syntax: explode(string separator, string string);

Returns an array, and each small string divided by separator is saved in the array.

So:

result_array=explode(" ", result_string); file://Use string " " to split the result

We get an array result_array, where each element is a search result entry. All we have to do is study each entry and its HTML display format code, and then replace it as required. The following uses a loop to process each entry in result_array.

 for( i=0; i {

... file:// handles each entry

 }

For each entry, we can easily find some characteristics: each entry is composed of title, abstract, introduction, category, URL, etc. Each part is line-wrapped, that is, it contains tags, so it is divided again: (The following processing The program is placed in the loop above)

every_item=explode(" ", result_array[ i]);

In this way we get an array every_item, where every_item[0] is the title, every_item[1] and every_item[2] are two lines of summary, every_item[3] and every_item[4], etc., if the header contains "Introduction: ", "< font size=-1 color=#6f6f6f>Category:< /font>" characters, it is an introduction or category (because some result entries do not have this item), if the header contains "< font color =green>" then it must be the URL. We often use regular expressions (omitted) for this comparison. It is also very convenient if you want to replace it. For example, $every_item[0] containing the title has a link in itself. We hope Modify the properties of this link so that it opens the link in a new window:

echo eregi_replace(' {

... file://processes every item in each entry except the first item (the first item is the title, which has been displayed)

... file://More format modifications

 }

In this way, the link attribute is modified, and many other display format modifications, stripping, and replacements can be completed using regular replacement eregi_replace().

At this point we have obtained each item of each search item, and can modify the format of each item arbitrarily, and even put a beautiful table on it. However, a good program should be able to adapt to various operating environments, and here is no exception. In fact, we have only discussed a framework method for HTML stripping of search results. To really do it perfectly, there are many things to consider, such as It displays the total number of search results, how many pages it is divided into, etc. It can even remove the "category", "introduction" and other codes related to Google, so that customers cannot see the original website at all. However, we can all extract these contents and requirements by analyzing HTML. Now everyone can do it themselves and build a highly personalized search engine.

What are the differences between websites developed with php and asp?

A simple understanding is: ASP technology is simple and can meet most of the needs of website construction. The technical threshold of engineering plastics is low, and the corresponding technical cost is also relatively low. It is currently common in the market. Let me analyze it in detail with you. My point of view: 1. Do you want to understand what PHP and ASP are? The simple understanding is: ASP technology is simple and can meet most of the needs of website construction. The technical threshold of engineering plastics is low, and the corresponding technical cost is also relatively low. It is a commonly used technology in the market. The technical threshold of PHP technology is slightly higher, and the technical cost is higher than that of ASP. However, with the gradual deepening of PHP application, the current cost of PHP website construction has been reduced to an acceptable level. It is an inevitable trend for PHP website construction technology to replace ASP technology in the website construction industry. 2. Running PHP script programs is very fast, surpassing ASP. Nowadays, large websites are basically developed using PHP, such as the website of Industrial and Commercial Bank of China. 3. Most PHP hosts support pseudo-static technology, while ASP hosts basically do not support this technology. Search engines will not regard it as an imitation site or a garbage site. This is very important for the promotion of engineering plastics on the website. Moreover, most of the websites on the Internet are ASP websites, and there are far fewer websites developed by PHP. Search engines are also fond of the new and dislike the old, which is more conducive to the optimization and promotion of the website. Such websites will also facilitate enterprises to implement online marketing and bid farewell to traditional industries. . 4. ASP technology is very mature and common, which makes it very convenient for designers to design, and naturally the cost is much lower. A simple website can be built by a designer in 1-2 days. Websites developed in PHP have relatively high technical requirements and are naturally more difficult. This requires a greater workload, so the production labor cost is relatively high. 5. Using PHP technology will provide higher quality website construction technology. Generally, DIV+CSS will be used. The page size can be minimized and the keyword density is the highest.

What is the PHP engine program?

Are you talking about PHP’s search engine or template engine.

Search engines such as PhpDig
are a web crawler and search engine developed using PHP. Build a vocabulary by indexing dynamic and static pages. When searching for a query, it will display search result pages containing keywords according to certain sorting rules. PhpDig includes a template system and can index PDF, Word, Excel, and PowerPoint documents. PhpDig includes the three most basic search engine technologies: Spider technology, web page structured information extraction technology or metadata collection technology, and word segmentation/indexing technology. Different from traditional search engines, PHPdig is suitable for more specialized and deeper personalized search engines. Using it to build a vertical search engine for a certain field is the best choice.

There are many such open source and free php search engines: OpenWebSpider, RiSearch PHP
, Sphider, Snoopy, Sphinx, SEO Rank Checker, PHPCrawl,

There are also many template engines:
Smarty is a template engine written in PHP and is currently one of the most famous PHP template engines in the industry. It separates logical code and external content, providing an easy-to-manage and use method to logically separate PHP code that is originally mixed with HTML code. Simply put, the purpose is to separate PHP programmers from front-end personnel, so that programmers change the logical content of the program without affecting the page design of the front-end personnel, and front-end personnel re-modify the page without affecting the program logic of the program. This is particularly important in projects involving multi-person collaboration.
Heyes Template Class
A very easy to use, yet powerful and fast template engine that helps you separate page layout and design from code.
FastTemplate
A simple variable interpolation template class, it analyzes your template and separates the variable values ​​​​from the HTML code.

ShellPage
A simple and easy-to-use class that can make your entire website layout based on template files. Modifying the template can change the entire site.

STP Simple Template Parser
A simple, lightweight and easy-to-use template parsing class. It can assemble a page from multiple templates and output the resulting page to the browser or file system.

OO Template Class
A cash-oriented template class that you can use in your own programs.

SimpleTemplate
A template engine that can create and structure websites. It can parse and compile templates.

bTemplate
A short but fast template class that allows you to separate PHP logic code from HTML decoration code.

Savant
A powerful and lightweight PEAR compatible template system. It is non-compiled and uses the PHP language itself as its template language.

ETS - easy template system
A template system that can reorganize templates using exactly the same data.

EasyTemplatePHP
A simple but powerful template system for your site.

vlibTemplate
A fast, all-in-one template system that includes a caching and debugging class.

AvanTemplate
A multi-byte safe template engine that takes up very little system resources. It supports variable substitution, and content blocks can be set to show or hide.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/891595.htmlTechArticleFull analysis of PHP development search engine technology, php development search engine When talking about web search engines, many people will think of Yahoo . Indeed, Yahoo created an era of Internet search. However...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!