Re: String to Meta Keyword list

From: Date: Fri, 21 Jul 2000 19:37:14 +0000
Subject: Re: String to Meta Keyword list
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-7619@lists.php.net to get a copy of this message
on 7/21/00 11:56 AM, lance@dallypost.com at lance@dallypost.com wrote: > I want to take a string (user defined product description) and > remove duplicate words and meaningless words such as "and, or, > etc" and then use it as keyword list for a meta tag. > > Any ideas as to the best way to do this? Well, you could use regular expressions or various string/array operations to count the frequency of each word, eliminate duplicates, etc. i.e. do something like $words = explode(" ", $input); // this can get way more fancy, but right now its just breaking up by spaces $uniquewords = array(); $badwords = array("and","or","if"); for ($i =0; $i<sizeof($words); $i++) { $word = strtolower($words[$I]); if (!in_array($word,$badwords)) { $uniquewords[$words[$i]]++; } } Then run iterate thu the $uniquewords array for the keys--they are the unique words. The values are the number of times they appear in $input. Obviously you'd want to do this once and store the metatags in a database... doing it at runtime would be ludicrous. -k

« previous php.general (#7619) next »