'; echo '
'; $q = $_GET['q']; $q = urlencode($q); $start = $_GET['start']; if (is_null($start)) $start=1; $your_cx_number="00226918842645167219:z234rys-low"; $url = "http://www.google.com/cse?cx=".$your_cx_number."&client=google-csbe&output=xml_no_dtd&q=$q&start=$start"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s curl_setopt($ch, CURLOPT_GET, 1); // set POST method //curl_setopt($ch, CURLOPT_POSTFIELDS, "postparam1=postvalue"); // add POST fields //submit the xml request and get the response $result = curl_exec($ch); curl_close($ch); //now parse the xml with $xml = simplexml_load_string($result); $START = $xml->RES[SN]; $END = $xml->RES[EN]; $RESULTS = $xml->RES->M; echo "

Outbound Query: $url


"; //NUM OF RESULTS IS INACCURATE; DO NOT USE //http://www.google.com/cse/docs/resultsxml.html#results_xml_tag_M //echo "Number of Results: $RESULTS
"; //extract the title, link and snippet for each result if ($xml->RES->R) { foreach ($xml->RES->R as $item) { $title = $item->T; $link = $item->U; $snippet = $item->S; echo "

$title
"; echo $snippet; echo "

"; } } $start = $start+10; echo "
Next

"; echo ""; ?>