<?php 
$criterion = @htmlentities($_GET["criterion"], ENT_NOQUOTES);
if(strpos($criterion, "\"")){
	$criterion = stripslashes($criterion);
	echo "<b>$criterion</b>"."</p><hr style=\"border:1px dotted black\" />";
}else{
	echo "\"<b>$criterion</b>\".</p><hr style=\"border:1px dotted black\" />";
}
//tu podaj stronę
$query = $criterion . " site:helion.pl";
//tu wpisz klucz Google
$key = "ykBRCBlQFHLzpfwtMTvfyj0Ssxa9niWY";
$maxresults = 8;
$start = 0;
try{
  $client = new SoapClient("http://api.google.com/GoogleSearch.wsdl");
  /*
  doGoogleSearchResponse  doGoogleSearch (string key, string q, int start, int
  maxResults, boolean filter, string restrict, boolean safeSearch, string lr,
  string ie, string oe)
  */
  $results = $client->doGoogleSearch($key, $query, $start, $maxresults, false,
      '',false, '','','' );
  /*
  GoogleSearchResults składa się z 
  documentFiltering, searchComments, estimatedTotalResultsCount,
  estimateIsExact,  resultElements, searchQuery, startIndex, 
  endIndex, searchTips, directoryCategories, searchTime 
  */
  $searchtime = $results->searchTime;
  $total = $results->estimatedTotalResultsCount;
  if($total > 0){ 
    //pobiera tablicę elementów 
    $re = $results->resultElements;
    /*
    ResultElements składają się z
    summary, URL, snippet, title, cachedSize, relatedInformationPresent,
    hostName, directoryCategory, directoryTitle
    */   
    foreach ($re as $value){
      $strtemp = "<a href= \"$value->URL\"> ".
        " $value->URL</a> $value->snippet<br /><br />\n";
      echo $strtemp;
    }  
    echo "<hr style=\"border:1px dotted black\" />";
    echo "<br />Czas wyszukiwania: $searchtime sekund(y).";
  }else{
    echo "<br /><br />Brak wyników wyszukiwania.";    
  }
}
catch (SOAPFault $exception){
  //echo $exception;
  echo "Nie można przetworzyć żądania.";
}
?>

