title: Extract/decode variable from JSON string
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1268792/how-to-decode-a-json-string-in-php">How to decode a JSON string in PHP?</a>  </p>
  </blockquote>
  
  
  
  <p>I would like to extract the variable <code>'name'</code> from the json string <code>$jsonstring</code>;</p>
  
  <pre><code>&lt;?php
  
  $facebookid = $_GET['fbid'];
  $facebooklink = 'http://graph.facebook.com/'.$facebookid.'?fields=name';
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $facebooklink);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  $jsonstring = curl_exec($ch);
  curl_close($ch);
  
  ?&gt;
  </code></pre>
  
  <p><code>$jsonstring</code> would output something like the following:</p>
  
  <pre><code>{
     "name": "THIS PART IS WHAT I WANT",
     "id": "4"
  }
  </code></pre>
  
  <p>I would like to extract the 'this part is what i want' from the above example.</p>
  
  <p>I have tried using json_decode but couldn't get it working, I have since deleted that code and therefore cannot write it here. Thanks for any help.</p>