blog
copyright ©
creamu Inc. All Rights Reserved.
art direction & design: Kunitaka Kawashimo
code, interaction & photography: creamu Inc.
category: Technology

PHPでRakuAPI。simplexml

Pocket

RakuAPI 楽天のアフィリエイトをxml等で返してくれるAPIが公開されていますね。 → RakuAPI Version 0.9 – 楽天市場非公式ウェブサービス PHPのsimplexmlを使って実装してみました。 例えば、ラッドミュージシャンの楽天商品をparseしたい場合、下記のようになります。 <?php $xml = simplexml_load_file("http://rakuapi.ddo.jp/api?query=ラッドミュージシャン&affiliate_code=0360b5e2.af9a2239&output=xml"); foreach($xml->Result as $item){ mb_convert_encoding("UTF-8", "Shift-JIS", $xml); if(strpos("ラッドミュージシャン",$item->Title)!==false){ $title = $item->Title; }else{ $title = null; } $img = $item->ThumbnailUrl; $url = $item->url; $rating = $item->rating; $price = $item->price; $rating = $item->rating; $word = "ラッドミュージシャン"; if (!ereg($title, $word)) { echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">". "<br>"."<a href=$url>$title</a>"."<br>"."<a href=$url><img src=$img border=\"0\" alt=$title></a>".$rating.$price; }else{ echo null; } } ?> 簡単ですね。 なんでもできそうです。 ※simplexmlを使うにはPHP5の環境が必要です。