Goodreads Developers discussion

80 views
questions > API with Php

Comments Showing 1-2 of 2 (2 new)    post a comment »
dateDown arrow    newest »

message 1: by Koushik (new)

Koushik Das (koushik72) | 1 comments How do I parse response in PHP?


$url = "https://www.goodreads.com/search.xml?...

$contents = file_get_contents($url);

print_r($contents);


It gives me the content but not in an array format.


$url = "https://www.goodreads.com/search.xml?...

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$contents = curl_exec($curl);
curl_close($curl);

print_r($contents);


It doesn't give me any result at all.

Please tell me how I can get the response from the API in PHP.
Thanks in advance.


message 2: by Laura (last edited Jun 20, 2016 08:40AM) (new)

Laura | 3 comments Hi Koushik,

Instead of print_r($contents), try something like this:

<?php $url = "https://www.goodreads.com/search.xml?...
$contents = file_get_contents($url);
$read_books_array = new SimpleXMLElement($contents);
?>

To return the results as an array:
<?php
var_dump($read_books_array);
?>


back to top