Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Bing
- preg_match_all('(<div class="sb_tlst">.*<h3>.*<a href="(.*)".*>(.*)</a>.*</h3>.*</div>)siU',$c_bing, $r_bing);
- // Google
- preg_match_all("@<h3\s*class=\"r\">\s*<a[^<>]*href=\"([^<>]*)\"[^<>]*>(.*)</a>\s*</h3>@siU",$c_google,$r_google);
- // Yahoo
- preg_match_all('(<h3><a class.*href="(.*)".*>(.*)</a>)siU',$c_yahoo,$r_yahoo);
- $final_results = array();
- $final_results_score = array();
- $fcount = 0;
- for ($i = 0; $i < count($r_bing[2]); $i++){
- // add all the bing results to the final results directly
- $final_results[$fcount] = $r_bing[1];
- $final_results_score[$fcount] = (10-$i); // more score more priority, so the rank 1 has 10 score
- $fcount++;
- }
- for ($i = 0; $i < count($r_google[2]); $i++){
- // now while adding google results check if the result already exist in the final_results
- for($j = 0; $j < $fcount; $j++){
- if($final_results[j] == $r_google[1]){
- // if already exist you need not re-add it, but increase its score
- $final_results_score[$j] += (10-$i);
- }
- else{
- // if not, just add it to the list
- $final_results[$fcount] = $r_google[1];
- $final_results_score[$fcount] = (10-$i); // more score more priority, so the rank 1 has 10 score
- $fcount++;
- }
- }
- }
- // the same procedure to the yahoo results
- for ($i = 0; $i < count($r_yahoo[2]); $i++){
- for($j = 0; $j < $fcount; $j++){
- if($final_results[j] == $r_yahoo[1]){
- $final_results_score[$j] += (10-$i);
- }
- else{
- // if not, just add it to the list
- $final_results[$fcount] = $r_yahoo[1];
- $final_results_score[$fcount] = (10-$i);
- $fcount++;
- }
- }
- }
- // now that you have all the results without repeatation and also their scores
- // use bubble sort algorithm to arrange them in order and you are done!
Add Comment
Please, Sign In to add comment