All pastes #635053 Raw Edit

Miscellany

public text v1 · immutable
#635053 ·published 2007-07-26 20:22 UTC
rendered paste body
<?php
function google($val)
{
  $fp = fsockopen("www.google.com", 80, $errno, $errstr, 30);
  if (!$fp) {
    return "err: $errstr ($errno)";
  } else {
    $out = "GET /search?hl=en&ie=UTF-8&oe=UTF-8&q=".urlencode($val)."&btnI=I%27m+Feeling+Lucky HTTP/1.1\r\n"
    ."Host: www.google.com\r\nConnection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
      $out=fgets($fp);
      if (substr($out,0,10) == 'Location: ')
      {
        fclose($fp);
        return substr($out,10);
      }
    }
    return 'No Results Found';
  }
}
?>