Question: I have designed a website in php language. I have a search box in my website. Now i want to make it usable means that if a user wants to search anything he could just type there and can get the desired result. Is this necessary to use php or it could be happened easily with HTML tags???

Answer: 
Basic Search
------------

Most simple searches on sites don't search the site's structure, they use the LIKE syntax in MySQL to find terms in the text fields of the related database tables. So, if you have a blog, you can let your users search inside the body of the blog in this way and return a list of entries with that term. With some clever counting, you can even order that list by how many times the term appears.

In these cases when the user types "taco" into the search box and hits enter, the user is taken to a PHP page that runs the LIKE query on the database and presents the user with blog posts that have the word Taco in them.

Real Search
-----------

Strictly speaking the above isn't a site search. If you have a site with lots of flat HTML pages and other pages that aren't inside of a database in some way, you will need to have your site crawled and expose data through a search on that data. [Google can set you up with this.](http://www.google.com/cse/) You also can use various 3rd party tools. However, it might be a good exercise to learn how to build a web crawler yourself.

Here are the essential steps to a web crawler that will generate a database of URLs. This rabbit hole extends forever, so this is only the barest minimum you need to do to have a working search.

### Database

Your database will have one single table. This table needs these fields:

* (int) ID
* (var\_char) URL
* (text) Text
* (timestamp) LastChecked

### Crawler

The crawler itself will need to either run continually or run every few minutes with a cron scheduler. It needs to perform these bare minimum actions:

1. Load a page from the database with the oldest LastChecked time. (or the root page if no pages are in the database)
2. Update LastChecked time.
3. Use cURL or other method to get the HTML from the page.
4. If the text content of the page has changed, update the database record for this URL.
5. Find all the anchor tags `<a href="http://www.mysite.com/taco/">Tacos!</a>` on the page and create an array of all these URLs.
6. Prune all the links from the list that aren't on your site. (otherwise, you will be crawling the web at large)
7. If the URL isn't already in the database, add it. Harvest the text of the page and insert that at the same time.
8. Repeat from 1.

Obviously this will only create a listing of all your pages and what text is on them, but that is enough to enable you to use the same technique from Basic Search to create a search for your site.

### Improvements

You can improve the above crawler in a few easy ways.

* Add an 'error' field on the table. If the URL has an HTML error code and no data, store the code. You can exclude these from your search and it will work like a handy link checker at the same time.
* You can add a new table for ranking where you store: the URL ID, a count, and the checked status of the URL. Run through every URL on the site as normal and update the counts on this table. Once all of the URLs from the master list are checked, move the 'count' to a new 'rank' field in the main table. Dump the ranking table and start over. You'll have a continually updating page rank which you can order your results by.
* You can gather automatic 'Last Changed' data by storing an MD5 hash of the full page's contents each time you crawl it, whenever you re-crawl a page and this MD5 changes, you store the new text and add to a new table a timestamp of when it changed and the URL ID. With this data you can build an expected change rate for pages. You can then add a 'Offset' field to the main table and add that to all the timestamps for LastChecked. This way, you re-order the main list to recheck some pages more often than others because they update more.
You can't perform this sort of functionality with HTML tags. PHP isn't *technically* necessary (there are alternatives), but in your case the likely answer is: yes, you need to use PHP.