文件内容读入 PHP

File Contents read in PHP

我可以使用以下代码PHP 中的google 本书获取信息

 $page1 = file_get_contents("https://www.googleapis.com/books/v1/volumes?q=isbn:1933372826")
 $data = json_decode($page1, true);

我有一个包含 1,200 多个 ISBN 的数组,所以我希望能够获取这些文件以便阅读它

因此,例如,如果我将 ISBN 数组的每个元素设为 $book_isbn,我尝试了以下操作,但出现错误

 $page2 = file_get_contents("https://www.googleapis.com/books/v1/volumes?q=isbn:$book_isbn")
 $book_data = json_decode($page2, true);

我应该改变什么?我可以在 file_get_contents 中加入 $book_isbn 吗?

这是我得到的错误

 Parse error: syntax error, unexpected '$book_data' (T_VARIABLE)

您可以使用

$book_isbn = '1933372826';
$page2 = file_get_contents("https://www.googleapis.com/books/v1/volumes?q=isbn:$book_isbn");
$book_data = json_decode($page2, true);
echo '<pre>';print_r($book_data);

如果 book_isbn 有多个值,则使用 foreach 并遍历每个元素。