title: Using the JSON data returned by the last.fm api
body: <p>I am trying to pull the top 6 artists from last.fm using the last.fm api.  I am able to pull in the JSON data and output it just fine.  However, when it comes to actually using specific pieces of data, I am at a loss. The only thing that I want to use is the artists' names. Here is the code I have so far.</p>
  
  <pre><code>&lt;?php
      $content = get_data('http://ws.audioscrobbler.com/2.0/?method=chart.gettopartists&amp;api_key=xxxxxxxxxxxxxx&amp;format=json&amp;limit=6');
      foreach ($content-&gt;artist as $artist) {
  echo '&lt;li&gt;';
  echo "{$artist-&gt;name}\n";
  echo '&lt;/li&gt;';
  }
  function get_data($url) {
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
  }           
  ?&gt;
  </code></pre>
  
  <p>The data looks like this:</p>
  
  <pre><code>{"artists":{"artist":[{"name":"Coldplay","playcount":"757749","listeners":"111884","mbid":"cc197bad-dc9c-440d-a5b5-d52ba2e14234","url":"http:\/\/www.last.fm\/music\/Coldplay","streamable":"1","image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34\/210303.jpg","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64\/210303.jpg","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/210303.jpg","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/252\/210303.jpg","size":"extralarge"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/500\/210303\/Coldplay.jpg","size":"mega"}]},{"name":"Rihanna","playcount":"943551","listeners":"102321","mbid":"69989475-2971-49aa-8c53-5d74af88b8be","url":"http:\/\/www.last.fm\/music\/Rihanna","streamable":"1","image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34\/79835799.png","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64\/79835799.png","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/79835799.png","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/252\/79835799.png","size":"extralarge"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/_\/79835799\/Rihanna+PNG.png","size":"mega"}]}}}
  </code></pre>
  
  <p>Any help would be greatly appreciated!</p>