Site Fuse! programming, design, hosting, promotion and advertising tips for webmasters
Design    Programming    Hosting    Classifieds

php stop words function


Important: The following is a text only archive!
For full features; Go to php stop words function

posted by MrPhear This simple php script is a function that takes a list of stop words (commonly occuring words that are of no use to a search engine) and strips them out of a variable term. This is similar to google removal of common words.

function stopWords($term, $stopwords_file)
{
//load list of common words
$common = file($stopwords_file);
$total = count($common);
for ($x=0; $x<= $total; $x++)
{
$common[$x] = trim(strtolower($common[$x]));
}

//make array of search terms
$_terms = explode(" ", $term);

foreach ($_terms as $line)
{
if (in_array(strtolower(trim($line)), $common))
{
$removeKey = array_search($line, $this->_terms);
unset($_terms[$removeKey]);
}
else
{
$clean_term .= " ".$line;
}
}
return $clean_term;
}
?>