Listing Google Spreadsheet answers with PHP (Parsing JSON)


/ Published in: PHP
Save to your folder(s)

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

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.