Warning: Invalid argument supplied for foreach() in /home/sites/heteml/users170/c/r/e/creamuinc/web/blog.creamu.com/phpbiyori/rakuapi/index.php on line 16
RakuAPIを使って、PHPに関する本を表示してみました。
PHP4で使えます。
pearから下記のファイルをダウンロードしてrequireするファイルパスに置いてください。
XML/Parser.php
XML/Unserializer.php
ソースは下記。
<?php
/*▽********************************XML_Unserializer************************************************/
require_once("../XML/Unserializer.php");
$base = "http://rakuapi.ddo.jp/api?query=PHP&genre=book&sort=low&affiliate_code=0360b5e2.af9a2239&output=xml";
$xmldoc = join("",file($base));
$opt = array (
'complexType' => 'object',
'parseAttributes' => 'true',
'attribuesArray' => '_attributes',
);
$xml = new XML_Unserializer($opt);
$xml -> unserialize($xmldoc, false);
$data = $xml->getUnserializedData();
foreach($data->Result as $item){
$title = $item->Title;
$img = $item->ThumbnailUrl;
$url = $item->Url;
echo "<a href=$url target=\~_blank\" onfocus=\"this.blur()\"><img src=$img border=\"0\" alt=$title></a>";
}
/*▲********************************XML_Unserializer************************************************/
?>

