PDA

View Full Version : Check url/string for certain words


Nightfire
11-15-2002, 12:56 AM
I'm creating a search engine, and I'm trying to use the same feature as google does. If you use a search which contains the words, and, or, if, etc, then it displays a message saying that the text hasn't been included in the search. How can I do this?

The url will be something like:
search.php?search=and+a+if+or+a

firepages
11-15-2002, 01:50 AM
well there are loads of approaches to this, & this is only 1


<?
$url='and+a+if+yaks+are+or+cooler+a+than+llamas';

/*array of no words*/
$no=array('and','a','if','or','a','are');

function lose_stuff(&$array,$no){
while(list($key,$var)=each($array)){
if(in_array($var,$no)){
unset($array[$key]);
$no_incs[]=$var;
}
}
return $no_incs;
}

$search = explode('+',$url);
$errs=lose_stuff($search,$no);

echo 'Sorry but the words '.implode(',',$errs).' were not included';
echo '<br />searching for ... '.implode(',',$search);
?>


I am sure there are better ways but its a start?