当前位置:首页 > PHP教程 > php应用 > 列表

php根据isbn书号查询amazon网站上的图书信息的示例

发布:smiling 来源: PHP粉丝网  添加日期:2020-09-14 15:50:01 浏览: 评论:0 

这篇文章主要介绍了php根据isbn书号查询amazon网站上的图书信息的示例,需要的朋友可以参考下。

插件说明:

插件根据提供的10位ISBN书号,在Amazon网站上查找该图书的详细信息。

如果找到结果,则返回一个两元素的数组,其中第一个元素是书的标题,而第二个元素是该书封面缩写图的URL地址。

它需要以下参数:$ISBN 10位ISBN书号。

  1. $isbn   = '007149216X'; 
  2. $result = PIPHP_GetBookFromISBN($isbn); 
  3. if (!$result) echo "Could not find title for ISBN '$isbn'."; 
  4. else echo "<img src='$result[1]' align='left'><b>$result[0]"; 
  5.   
  6. function PIPHP_GetBookFromISBN($isbn) 
  7. { 
  8.    // Plug-in 93: Get Book From ISBN 
  9.    // 
  10.    // This plug-in looks up an ISBN-10 at Amazon.com and then 
  11.    // returns the matching book title and a thumbnail image 
  12.    // of the front cover. It requires this argument: 
  13.    // 
  14.    //    $isbn: The ISBN to look up 
  15.    // 
  16.    // Updated from the function in the book to take into 
  17.    // account changes to the Amazon HTML. 
  18.   
  19.    $find = '<meta name="description" content="Amazon:'; 
  20.    $url  = "http://www.amazon.com/gp/aw/d.html?a=$isbn"; 
  21.    $img  = 'http://ecx.images-amazon.com/images/I'; 
  22.   
  23.    $page = @file_get_contents($url); 
  24.    if (!strlen($page)) return array(FALSE); 
  25.   
  26.    $ptr1 = strpos($page, $find) + strlen($find); 
  27.    if (!$ptr1) return array(FALSE); 
  28.   
  29.    $ptr2  = strpos($page, '" />', $ptr1); 
  30.    $title = substr($page, $ptr1, $ptr2 - $ptr1); 
  31.    //phpfensi.com 
  32.    $find = $img; 
  33.    $ptr1  = strpos($page, $find) + strlen($find); 
  34.    $ptr2  = strpos($page, '"', $ptr1); 
  35.    $image = substr($page, $ptr1, $ptr2 - $ptr1); 
  36.   
  37.    return array($title, $img . $image); 
  38. } 

Tags: php书号查询 amazon

分享到: