title: Output Google Search Results Using PHP?
body: <p>I have looked at several old answers on stackoverflow but they are all out-dated and the API they used is no longer available.</p>
  
  <p>I have created a JSON/Atom API, CX key and used a script Thanks to Adam Fischer I found on here but when I'm trying am now able to output print the results on the page I'm getting with the error:</p>
  
  <blockquote>
    <p>Notice: Undefined property: stdClass::$responseData in
    E:\XAMPP\htdocs\PHP Training\google.php on line 19</p>
    
    <p>Notice: Trying to get property of non-object in E:\XAMPP\htdocs\PHP
    Training\google.php on line 19</p>
  </blockquote>
  
  <p>This is what I have so far. below code.</p>
  
  <pre><code>$url = 'https://www.googleapis.com/customsearch/v1?key=[MY API KEY]&amp;cx=[MY CX KEY]&amp;q=lecture';
  
  $body = file_get_contents($url);
  $json = json_decode($body);
  
  for($x=0;$x&lt;countif ($json-&gt;responseData-&gt;results);$x++&gt;items){
  
  echo "&lt;b&gt;Result ".($x+1)."&lt;/b&gt;";
  echo "&lt;br&gt;URL: ";
  echoforeach ($json-&gt;responseData-&gt;results[$x]-&gt;url;
  echo&gt;items "&lt;br&gt;VisibleURL:as ";$item){
  echo $json-&gt;responseData-&gt;results[$x]-&gt;visibleUrl;
  echo "&lt;br&gt;Title: ";
  echo $json-&gt;responseData-&gt;results[$x]-&gt;title;
  echo "&lt;br&gt;Content: ";print_r($item)
  echo $json-&gt;responseData-&gt;results[$x]-&gt;content;
  echo "&lt;br&gt;&lt;br&gt;"; }
  }
  </code></pre>
  
  <p>The API is working correctly because when I visit This spits out everything in an array. Example: dl.dropboxusercontent.com/u/47731225/sample.txt</p>
  
  <p>I'm trying to make the $url I see results such as be displayed on my page like a Google Search, for example: prntscr.com/drum5u</p>
  
  <pre><code>{
     "kind": "customsearch#result",
     "title": "The Tank, Haydon Allen Lecture Theatre, Building 23, ANU",
     "htmlTitle": "The Tank, Haydon Allen \u003cb\u003eLecture\u003c/b\u003e Theatre, Building 23, ANU",
     "link": "https://www.google.com/mymaps/viewer?mid=1YGFZHcZ20jPvy5OiaKT1voy841Q&amp;hl=en",
     "displayLink": "www.google.com",
     "snippet": "\"The Tank\", Haydon Allen Lecture Theatre, Building 23, The Australian National \nUniversity (ANU), Canberra, Australia.",
     "htmlSnippet": "&amp;quot;The Tank&amp;quot;, Haydon Allen \u003cb\u003eLecture\u003c/b\u003e Theatre, Building 23, The Australian National \u003cbr\u003e\nUniversity (ANU), Canberra, Australia.",
     "cacheId": "hTeucZ5TewoJ",
     "formattedUrl": "https://www.google.com/mymaps/viewer?mid...hl=en",
     "htmlFormattedUrl": "https://www.google.com/mymaps/viewer?mid...hl=en",
     "pagemap": {
      "cse_thumbnail": [
       {
        "width": "221",
        "height": "228",
        "src": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSntx5YhQgJQeJ6RAZajOx7SGOwh0oUu8jtpY6VOAS75V_oNkiXx923ro4"
       }
  </code></pre>