Posted By

Felladrin on 05/02/12


Tagged

google json spreadsheet


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

icecreamboyy


Listing Google Spreadsheet answers with PHP (Parsing JSON)


 / Published in: PHP
 

Make your spreadsheet public to get a key like this: 0AsfENoKj1ir7dE8yR6U0aUtpdTVNM20wRlNJOhZaclG

Set it on the script and you're all done.

  1. <?php
  2. $key = '0AsfENoKj1ir7dE8yR6U0aUtpdTVNM20wRlNJOhZaclG';
  3. $json_string = file_get_contents("https://spreadsheets.google.com/feeds/list/$key/od6/public/values?alt=json");
  4. $obj = json_decode($json_string);
  5. foreach ($obj->{'feed'}->{'entry'} as $entry)
  6. {
  7. echo "<p>";
  8. $num_column = 0;
  9. $answer = explode(', ', $entry->{'content'}->{'$t'});
  10. foreach ($answer as $a)
  11. {
  12. $a = explode(': ', $a);
  13. if (isset($a[1]))
  14. {
  15. $a = $a[1];
  16. $num_column++;
  17. echo "<b>$num_column:</b> $a<br/>";
  18. }
  19. }
  20. echo "</p>";
  21. }
  22. ?>

Report this snippet  

You need to login to post a comment.