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

时间:2023-11-15 03:08:53 

插件说明:
插件根据提供的10位ISBN书号,在Amazon网站上查找该图书的详细信息。
如果找到结果,则返回一个两元素的数组,其中第一个元素是书的标题,而第二个元素是该书封面缩写图的URL地址。
它需要以下参数:$ISBN 10位ISBN书号


$isbn   = '007149216X';
$result = PIPHP_GetBookFromISBN($isbn);
if (!$result) echo "Could not find title for ISBN '$isbn'.";
else echo "<img src='$result[1]' align='left'><b>$result[0]";

function PIPHP_GetBookFromISBN($isbn)
{
   // Plug-in 93: Get Book From ISBN
   //
   // This plug-in looks up an ISBN-10 at Amazon.com and then
   // returns the matching book title and a thumbnail image
   // of the front cover. It requires this argument:
   //
   //    $isbn: The ISBN to look up
   //
   // Updated from the function in the book to take into
   // account changes to the Amazon HTML.

   $find = '<meta name="description" content="Amazon:';
   $url  = "http://www.amazon.com/gp/aw/d.html?a=$isbn";
   $img  = 'http://ecx.images-amazon.com/images/I';

   $page = @file_get_contents($url);
   if (!strlen($page)) return array(FALSE);

   $ptr1 = strpos($page, $find) + strlen($find);
   if (!$ptr1) return array(FALSE);

   $ptr2  = strpos($page, '" />', $ptr1);
   $title = substr($page, $ptr1, $ptr2 - $ptr1);

   $find = $img;
   $ptr1  = strpos($page, $find) + strlen($find);
   $ptr2  = strpos($page, '"', $ptr1);
   $image = substr($page, $ptr1, $ptr2 - $ptr1);

   return array($title, $img . $image);
}

标签:php,isbn,amazon
0
投稿

猜你喜欢

  • 浅谈python抛出异常、自定义异常, 传递异常

    2022-12-22 00:49:31
  • php的PDO事务处理机制实例分析

    2024-05-11 09:45:30
  • MySQL存储过程中使用动态行转列

    2024-01-16 22:03:16
  • sql注入与转义的php函数代码

    2023-07-16 11:20:15
  • 使用python实现UDP通信方式

    2021-09-19 13:48:35
  • 保护Access 2000数据库的安全

    2008-10-23 13:55:00
  • js实现关闭网页出现是否离开提示

    2024-05-09 10:36:13
  • Firebox 3 后退后按钮 diasabled 状态不恢复的一个解决方案

    2008-11-06 12:28:00
  • VS Code安装go插件失败原因分析以及解决方案

    2024-04-26 17:24:08
  • np.hstack()和np.dstack()的使用

    2021-02-03 12:52:15
  • 详解Django中的form库的使用

    2022-05-16 00:13:50
  • Python关于print的操作(倒计时、转圈显示、进度条)

    2022-08-19 07:26:58
  • 理解CSS3线性渐变

    2010-03-28 13:42:00
  • IE6,7下实现white-space:pre-wrap;

    2009-12-31 18:30:00
  • ASP中使用存储过程介绍

    2008-10-10 12:10:00
  • Python循环语句介绍

    2021-04-19 20:04:42
  • PHP中phar包的使用教程

    2023-11-09 19:55:52
  • Python机器学习性能度量利用鸢尾花数据绘制P-R曲线

    2023-01-27 20:55:48
  • Python使用Pandas库常见操作详解

    2022-12-10 09:03:13
  • xml文件调用css

    2008-09-05 17:12:00
  • asp之家 网络编程 m.aspxhome.com