I'LL GIVE IT A SH...Sorry, I mean I'll give it a shot (code formatted and posted so as to be readable):
// Create array of words to, pesumably, ignore, used as the array indexes
// (why not just an array of the words as values, I don't know):
$CommonWords = array("a" => 1, "as" => 1, "any" => 1, "all" => 1 , "am" => 1, "an" => 1, "and" => 1, "are" => 1, "at" => 1,
"b" => 1, "be" => 1, "but" => 1, "by" => 1,
"c" => 1, "can" => 1,
"d" => 1, "did" => 1, "does" => 1, "do" => 1,
"e" => 1, "each" => 1, "else" => 1, "even" => 1, "ever" => 1,
"f" => 1, "for" => 1, "from" => 1,
"g" => 1, "go" => 1, "get" => 1);
// This removes whitespace from the ends of the keyword phrase,
// and coverts it to lowercase to make word-matching easier:
$search_keywords = strtolower(trim($keywords));
// This makes an array of the separate words in the keyword phrase:
$arrWords = explode(" ", $search_keywords);
//remove duplicates
// This removes duplicate words from the keyword array:
$arrWords = array_unique($arrWords);
// Initialize arrays, not really needed:
$searchWords = array();
$junkWords = array();
// Iterate through the keyword array:
foreach ($arrWords as $word) {
//remove common words
// Notice level error generated if $word not in common word array;
// also if two consecutive spaces entered in keyword phrase,
// "" will be added to the search word array (not desired, I assume):
if(!$CommonWords[$word]){
// If the word is not in the common words array, i.e. if the key $word doesn't exist,
// keep it to use in the search:
$searchWords[] = $word;
} else {
// If it is in the common words array, store it (why?) as junk:
$junkWords[] = $word;
}
}
Here's a better (imo) and more sensible (imo), though not thoroughly robust, way to do it:
$CommonWords = array('a', 'as', 'any', 'all', 'am', 'an', 'and', 'are', 'at',
'b', 'be', 'but', 'by',
'c', 'can',
'd', 'did', 'does', 'do',
'e', 'each', 'else', 'even', 'ever',
'f', 'for', 'from',
'g', 'go', 'get');
$search_keywords = strtolower(trim($keywords));
$arrWords = explode(' ', $search_keywords);
$arrWords = array_unique($arrWords);
foreach ($arrWords as $word) {
if (!in_array($word, $CommonWords) && (trim($word) != '')) {
$searchWords[] = $word;
} else {
$junkWords[] = $word;
}
}