Google,like,search,function,with,bolded,search,terms,php

Mert 9/1/2016 0

Google like search function with bolded search terms in PHP

PHP
<? 

//Google like search engine for your site, 
//the $not_search_word array can be added to, 
//to limit the results even further for those 
//common words that should not be searched for. 


foreach ($searchwords as $word) { 
    /* 
    For each word, include any records that have all of the words in the field anywhere, 
    but the problem is, after this how to tell sql to combine all of these (if there were 
    several words)     and then insert them into sql statement. 
    */ 

    $not_search_word = array('if', 'for', 'in', 'on','and','with'); //add words as needed 
     
    echo "Only relevant search terms are searched. They are shown in bold below. 
          Words like in, for etc are not searched on as they are common words 
          and will skew results"; 

    echo "Search results for :"; 

    if (!in_array($word,$not_search_word)){  //relevant search term only 
        echo " <b>$word</b> "; 
        if ($x==1){ 
          $sql.= " fieldname like '%$word%' "; 
          $x  ; //increase the counter 
        }else 
          $sql .= "OR fieldname like '%$word%' "; 
        }//close if then 
    }else{ 
        echo $word; 
    }//end if 
}//close foreach loop 

//do the query 
//report the results 

//Have some fun with this one 
//bastien 
?>
 

Report Bug

Please Login to Report Bug

Reported Bugs

Comments

Please Login to Comment

Comments