Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. <?php
  2.  
  3. // Convert from Json to Key => Value masive
  4. $books = json_decode(file_get_contents("https://www.googleapis.com/books/v1/volumes?q=isbn%3A0716604892"), true);
  5.  
  6. //initialize masive
  7. $myData = array();
  8.  
  9. // get all books and added it to your masive
  10. foreach ($books["items"] as $book) {
  11. array_push($myData, $book["volumeInfo"]);
  12. }
  13.  
  14. //This should be in your view page
  15. foreach ($myData as $value) {
  16. echo "<h1>". $value["title"] . "</h1>";
  17.  
  18. echo "<div>Authors: ";
  19. for ($i=0; $i < count($value["authors"]); $i++) {
  20. echo $value["authors"][$i] ." ";
  21. }
  22. echo "</div>";
  23.  
  24. // Check if current book have image links
  25. if (isset($value["imageLinks"])) {
  26. echo "<br> <strong>Image links</strong>: <br>";
  27. foreach ($value["imageLinks"] as $key => $link) {
  28. echo $key ." => ". $link . "<br>";
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement