PHP Diary | PHP Housekeeping | PHP Scripts | TD Scripts.com
Online Offline Manager - Show the online/offline status of a group of users on a webpage


[back]
WB01624_.gif (281 bytes) 01/06/00 "Getting and using meta tags for search criteria" WB01626_.gif (272 bytes)[next]

Using Meta Tags for search results

Searching each HTML page for keywords could become pretty involved in a dynamic environment and put a lot of load on the server. It would be more efficient for me to allow users to search a smaller pool of specific information. While writing and creating these diary entries I have tried to use descriptive meta tags so that these diary entries would draw the attention of external search engines, but also so that when I got to the point where I would create an onsite or internal search engine, I'd have a useful pool of information to work with. Also, I went back through every page and updated the meta tags so that they would be properly indexing the content in that days diary entry.

You might be wondering if we could search through every diary page. Of course we could. We could create a search engine which would look through each HTML page and pull matches out, but as the number of diary entries and pages grew it would become more server intensive. Some of you may say, why do you care about the server, well as a programmer we have to care about the server. If you really wanted to search large groups of HTML pages in their entirety, it would be better to scan the output first and put the useful pieces of the text into a database (we will be exploring mySQL databases soon). For instance you would not likely need all the HTML tags so those could be removed to reduce the file size. Simply put, the more information php has to sift through the longer the search will take. PHP has a built-in function to easily fetch meta tags from php or html pages called the get_meta_tags function. It will take all the meta tags and build associative arrays with the name of the associative array being the meta name and value of the associative array being the contents of the meta tag. Associative arrays are something we haven't really discussed yet if you are coming along with me chronologically.

associative array  =    $meta["description"] = "This is one of my php diary pages";
                                $meta["keywords"] = "programming php meta tags";
                 array   =   $meta[0] = "This is array entry 1";
                                $meta[1] = "Array entry 2 - remember that numbering in arrays starts at zero";

Below I have shown how to fetch all the meta tags for this page and print them to the browser:

<?
$meta = get_meta_tags("010600.php3");
print($meta["description"]);
print("<br>");
print($meta["keywords"]);
?>

Example #21: using php to display the meta tags for this page

Now all we need to do to interface this with our search engine is compare the contents of the $meta variable to the $search_criteria from yesterday's diary entry and if we have a match display the appropriate link. Again, this is the basic concept of a search engine. Search engines often use much more elaborate algorithms. For this particular search engine scenario, I don't really need to do relevancy matches (yet), but I suspect we'll do something like this when we get to mySQL databases. Relevancy matches are essentially the more times keywords or combinations of words match the search criteria, the more relevant the match will be and thus the higher up the list. Since at the time of this writing I only have like 20 diary entries or so (and thus 20 different meta descriptions and sets of keywords) a sophisticated search algorithm is not needed at this time.

Please vote on what you think of this diary entry :)

How useful was this diary entry? Avg Surfer Rating: 3.85 (277)

[back]WB01624_.gif (281 bytes) 01/06/00 "Getting and using meta tags for search criteria" WB01626_.gif (272 bytes)[next]

PHP Diary | PHP Housekeeping | PHP Scripts | TD Scripts.com

Copyright 2000 php-scripts.com Last Modified 01/6/00 09:30