title: Get single value from PHP object array
body: <p>I am very new to PHP and I want to grab a single value from the OpenGraph object and print it. Not sure what I am doing wrong? I keep getting "Array" as the print out.</p>
  
  <pre><code>class OpenGraph implements Iterator{
  
  public static $TYPES = array(
      'activity' =&gt; array('activity', 'sport'),
      'business' =&gt; array('bar', 'company', 'cafe', 'hotel', 'restaurant'),
      'group' =&gt; array('cause', 'sports_league', 'sports_team'),
      'organization' =&gt; array('band', 'government', 'non_profit', 'school', 'university'),
      'person' =&gt; array('actor', 'athlete', 'author', 'director', 'musician', 'politician', 'public_figure'),
      'place' =&gt; array('city', 'country', 'landmark', 'state_province'),
      'product' =&gt; array('album', 'book', 'drink', 'food', 'game', 'movie', 'product', 'song', 'tv_show'),
      'website' =&gt; array('blog', 'website'),
  );
  
  private $_values = array();
  
  static public function fetch($URI) {
      $curl = curl_init($URI);
      curl_setopt($curl, CURLOPT_FAILONERROR, true);
      curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_TIMEOUT, 15);
      curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
      $response = curl_exec($curl);
      curl_close($curl);
      if (!empty($response)) {
          return self::_parse($response);
      } else {
          return false;
      }
  }
  
  static private function _parse($HTML) {
      $old_libxml_error = libxml_use_internal_errors(true);
      $doc = new DOMDocument();
      $doc-&gt;loadHTML($HTML);
  
      libxml_use_internal_errors($old_libxml_error);
      $tags = $doc-&gt;getElementsByTagName('meta');
      if (!$tags || $tags-&gt;length === 0) {
          return false;
      }
      $page = new self();
      $nonOgDescription = null;
  
      foreach ($tags AS $tag) {
          if ($tag-&gt;hasAttribute('property') &amp;&amp;
              strpos($tag-&gt;getAttribute('property'), 'og:') === 0) {
              $key = strtr(substr($tag-&gt;getAttribute('property'), 3), '-', '_');
              $page-&gt;_values[$key] = $tag-&gt;getAttribute('content');
          }
  
          //Added this if loop to retrieve description values from sites like the New York Times who have malformed it. 
          if ($tag -&gt;hasAttribute('value') &amp;&amp; $tag-&gt;hasAttribute('property') &amp;&amp;
              strpos($tag-&gt;getAttribute('property'), 'og:') === 0) {
              $key = strtr(substr($tag-&gt;getAttribute('property'), 3), '-', '_');
              $page-&gt;_values[$key] = $tag-&gt;getAttribute('value');
          }
          //Based on modifications at https://github.com/bashofmann/opengraph/blob/master/src/OpenGraph/OpenGraph.php
          if ($tag-&gt;hasAttribute('name') &amp;&amp; $tag-&gt;getAttribute('name') === 'description') {
              $nonOgDescription = $tag-&gt;getAttribute('content');
          }
  
      }
      //Based on modifications at https://github.com/bashofmann/opengraph/blob/master/src/OpenGraph/OpenGraph.php
      if (!isset($page-&gt;_values['title'])) {
          $titles = $doc-&gt;getElementsByTagName('title');
          if ($titles-&gt;length &gt; 0) {
              $page-&gt;_values['title'] = $titles-&gt;item(0)-&gt;textContent;
          }
      }
      if (!isset($page-&gt;_values['description']) &amp;&amp; $nonOgDescription) {
          $page-&gt;_values['description'] = $nonOgDescription;
      }
      //Fallback to use image_src if ogp::image isn't set.
      if (!isset($page-&gt;values['image'])) {
          $domxpath = new DOMXPath($doc);
          $elements = $domxpath-&gt;query("//link[@rel='image_src']");
          if ($elements-&gt;length &gt; 0) {
              $domattr = $elements-&gt;item(0)-&gt;attributes-&gt;getNamedItem('href');
              if ($domattr) {
                  $page-&gt;_values['image'] = $domattr-&gt;value;
                  $page-&gt;_values['image_src'] = $domattr-&gt;value;
              }
          }
      }
      if (empty($page-&gt;_values)) { return false; }
  
      return $page;
  }
  
  public function __get($key) {
      if (array_key_exists($key, $this-&gt;_values)) {
          return $this-&gt;_values[$key];
      }
  
      if ($key === 'schema') {
          foreach (self::$TYPES AS $schema =&gt; $types) {
              if (array_search($this-&gt;_values['type'], $types)) {
                  return $schema;
              }
          }
      }
  }
  
  public function keys() {
      return array_keys($this-&gt;_values);
  }
  
  public function __isset($key) {
      return array_key_exists($key, $this-&gt;_values);
  }
  
  public function hasLocation() {
      if (array_key_exists('latitude', $this-&gt;_values) &amp;&amp; array_key_exists('longitude', $this-&gt;_values)) {
          return true;
      }
  
      $address_keys = array('street_address', 'locality', 'region', 'postal_code', 'country_name');
      $valid_address = true;
      foreach ($address_keys AS $key) {
          $valid_address = ($valid_address &amp;&amp; array_key_exists($key, $this-&gt;_values));
      }
      return $valid_address;
  }
  
  private $_position = 0;
  public function rewind() { reset($this-&gt;_values); $this-&gt;_position = 0; }
  public function current() { return current($this-&gt;_values); }
  public function key() { return key($this-&gt;_values); }
  public function next() { next($this-&gt;_values); ++$this-&gt;_position; }
  public function valid() { return $this-&gt;_position &lt; sizeof($this-&gt;_values); }}
  </code></pre>
  
  <p>Implementation:</p>
  
  <pre><code>require_once('OpenGraph.php');
  $graph = OpenGraph::fetch('http://www.google.com');
  echo $graph-&gt;keys('description');
  </code></pre>
  
  <p>I actually got this code from a github here: <a href="https://github.com/scottmac/opengraph" rel="nofollow">https://github.com/scottmac/opengraph</a></p>