<HighlightSyntax>
- Googlefight implementation by mutante
function googlefight($term1, $term2) {
$url1 = "http://www.google.de/search?q=" . $term1; $url2 = "http://www.google.de/search?q=" . $term2;
$buffer1 = file_get_contents($url1);
$pieces1 = explode("hr ", $buffer1); $piece1 = $pieces1[1];
$pieces2 = explode("", $piece1);
$hits1 = $pieces2[0]; $hits1 = str_replace(".", "", $hits1); if (!is_numeric($hits1)) { $hits1 = 0; }
$buffer2 = file_get_contents($url2);
$pieces1 = explode("hr ", $buffer2); $piece1 = $pieces1[1];
$pieces2 = explode("", $piece1); $hits2 = $pieces2[0]; $hits2 = str_replace(".", "", $hits2);
if (!is_numeric($hits2)) { $hits2 = 0; }
$hits1 = intval($hits1); $hits2 = intval($hits2);
if ($hits1 > $hits2) { $hits1 = number_format($hits1); $hits2 = number_format($hits2); $output .= "Googlefight: '$term1' beat '$term2' with $hits1 to $hits2 hits."; } elseif ($hits1 == 0 AND $hits2 == 0) { $hits1 = number_format($hits1); $hits2 = number_format($hits2); $output .= "Googlefight: No results, both terms dont have any hits. ($hits1)"; } elseif ($hits1 == $hits2) { $hits1 = number_format($hits1); $hits2 = number_format($hits2); $output .= "Googlefight: Draw! Both terms have the same number of hits. ($hits1)"; } elseif ($hits2 > $hits1) { $hits1 = number_format($hits1); $hits2 = number_format($hits2); $output .= "Googlefight: '$term2' beat '$term1' with $hits2 to $hits1 hits."; } else { $output .= "Googlefight: unknown error fnord"; }
return $output;
} </HighlightSyntax>