Nightfire
01-04-2003, 09:59 AM
I'm having some real problems thinking of how to do this. I'm creating a search engine and I'm wanting to delete most used words out of the string ppl are searching for, ie:
$textentered = "a free house and car";
and delete the words a and and
So I'm wanting to split it at the spaces then check what's in each part splitted?
At the mo I'm using
$text = " hello";
$text = strtolower($text);
//$text = explode(" ",$text);
$text = ereg_replace(" is", "", $text);
$text = ereg_replace(" and", "", $text);
$text = ereg_replace(" or", "", $text);
$dbhost = "localhost";
$dbuname = "root";
$dbpword = "";
$dbname = "searchengine";
@mysql_connect($dbhost,$dbuname,$dbpword);
@mysql_select_db($dbname);
$sql = "SELECT * FROM `sites` WHERE description like '%$text%'";
$result = mysql_query($sql);
$affected = mysql_num_rows($result);
if($affected > 0){
while($row = mysql_fetch_array($result)){
$row[2] = ereg_replace("$text",'<font color="#ff0000">'.$text.'</font>',$row[2]);
echo $row[1].'<br>'.$row[2];
}
}else{
echo 'No results found';
}
When I use explode, I get "no results found" I think I need to use an array, but I don't understand them :confused:
Me so lost :(
$textentered = "a free house and car";
and delete the words a and and
So I'm wanting to split it at the spaces then check what's in each part splitted?
At the mo I'm using
$text = " hello";
$text = strtolower($text);
//$text = explode(" ",$text);
$text = ereg_replace(" is", "", $text);
$text = ereg_replace(" and", "", $text);
$text = ereg_replace(" or", "", $text);
$dbhost = "localhost";
$dbuname = "root";
$dbpword = "";
$dbname = "searchengine";
@mysql_connect($dbhost,$dbuname,$dbpword);
@mysql_select_db($dbname);
$sql = "SELECT * FROM `sites` WHERE description like '%$text%'";
$result = mysql_query($sql);
$affected = mysql_num_rows($result);
if($affected > 0){
while($row = mysql_fetch_array($result)){
$row[2] = ereg_replace("$text",'<font color="#ff0000">'.$text.'</font>',$row[2]);
echo $row[1].'<br>'.$row[2];
}
}else{
echo 'No results found';
}
When I use explode, I get "no results found" I think I need to use an array, but I don't understand them :confused:
Me so lost :(