Guest User

Untitled

a guest
Jun 23rd, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.73 KB | None | 0 0
  1. // Bing
  2. preg_match_all('(<div class="sb_tlst">.*<h3>.*<a href="(.*)".*>(.*)</a>.*</h3>.*</div>)siU',$c_bing, $r_bing);
  3.  
  4. // Google
  5. preg_match_all("@<h3\s*class=\"r\">\s*<a[^<>]*href=\"([^<>]*)\"[^<>]*>(.*)</a>\s*</h3>@siU",$c_google,$r_google);
  6.  
  7. // Yahoo
  8. preg_match_all('(<h3><a class.*href="(.*)".*>(.*)</a>)siU',$c_yahoo,$r_yahoo);
  9.  
  10.  
  11. $final_results = array();
  12. $final_results_score = array();
  13. $fcount = 0;
  14.  
  15. for ($i = 0; $i < count($r_bing[2]); $i++){
  16.     // add all the bing results to the final results directly
  17.    
  18.     $final_results[$fcount] = $r_bing[1];
  19.     $final_results_score[$fcount] = (10-$i); // more score more priority, so the rank 1 has 10 score
  20.     $fcount++;
  21. }
  22.  
  23. for ($i = 0; $i < count($r_google[2]); $i++){
  24.     // now while adding google results check if the result already exist in the final_results
  25.     for($j = 0; $j < $fcount; $j++){
  26.         if($final_results[j] == $r_google[1]){
  27.             // if already exist you need not re-add it, but increase its score
  28.             $final_results_score[$j] += (10-$i);
  29.         }
  30.         else{
  31.             // if not, just add it to the list
  32.             $final_results[$fcount] = $r_google[1];
  33.             $final_results_score[$fcount] = (10-$i); // more score more priority, so the rank 1 has 10 score
  34.             $fcount++;
  35.         }
  36.     }
  37. }
  38. // the same procedure to the yahoo results
  39. for ($i = 0; $i < count($r_yahoo[2]); $i++){
  40.  
  41.     for($j = 0; $j < $fcount; $j++){
  42.         if($final_results[j] == $r_yahoo[1]){
  43.             $final_results_score[$j] += (10-$i);
  44.         }
  45.         else{
  46.             // if not, just add it to the list
  47.             $final_results[$fcount] = $r_yahoo[1];
  48.             $final_results_score[$fcount] = (10-$i);
  49.             $fcount++;
  50.         }
  51.     }
  52. }
  53.  
  54. // now that you have all the results without repeatation and also their scores
  55. // use bubble sort algorithm to arrange them in order and you are done!
Add Comment
Please, Sign In to add comment