Jnerocorp Posted November 5, 2009 Share Posted November 5, 2009 Hello, I am getting this error: PHP Warning: fread(): supplied argument is not a valid stream resource in /home/jnero/public_html/querygoogle.php on line 20 here is the code: querygoogle.php: <?php session_start(); if(isset($_GET['searchquery'])) { $searchquery = $_GET['searchquery']; $searchquery = str_replace(" ","+",$searchquery); // if you use an Mike Migurski's JSON library, include it like I did require_once('JSON.phps'); // Here's the Google AJAX Search API url for curl. It uses Google Search's site:www.yourdomain.com syntax to search in a specific site. I used $_SERVER['HTTP_HOST'] to find my domain automatically. Change $_POST['searchquery'] to your posted search query $url ="http://ajax.googleapis.com/ajax/services/search/web?rsz=large&v=1.0&q=$searchquery"; // use fopen and fread to pull Google's search results $handle = fopen("$url", "rb"); while(!feof($handle)) { $body .= fread($handle, filesize($url)); } fclose($handle); // now $body is the JSON encoded results. We need to decode them. $json = new Services_JSON(); $json = $json->decode($body); // now $json is an object of Google's search results and we need to iterate through it. foreach($json->responseData->results as $searchresult) { if($searchresult->GsearchResultClass == 'GwebSearch') { $formattedresults .= ' <div class="searchresult"> <h3><a href="' . $searchresult->unescapedUrl . '">' . $searchresult->titleNoFormatting . '</a></h3> <p class="resultdesc">' . $searchresult->content . '</p> <p class="resulturl">' . $searchresult->visibleUrl . '</p> </div>'; } } $query = $_GET['searchquery']; $query = str_replace(" ","+",$query); $murl = "http://mydomainpagerank.com/search2/index.php?search=$query"; $_SESSION['googleresults'] = $formattedresults; header('Location: ' . $murl); exit; } ?> Link to comment https://forums.phpfreaks.com/topic/180373-php-warning-fread-supplied-argument-is-not-a-valid-stream-resource-in/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.