stargeek
PHP news website logo.
home    PHP scripts    articles    seo tools    links    search    contact    shop    realtors

stop words function






Stargeek's PHP Scripts

Please select a category:

View All Scripts
xmlsql
blogseo
statisticsmisc
 

Search Stargeek's PHP Scripts Database


Want to get this PHP script installed on your site?

Get this script installed by the author.

stop words function This simple php script is a function that takes a list of stop words (commnly 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.

<?php
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;    
    }
?>