久しぶりにValueCommerceにログインしました(笑)
<!DOCTYPE html> <html lang='ja'> <head> <title>API</title> <meta charset='utf-8'> </head> <body> <?php $yahoo_result = getYahooResult('ヴィトン'); foreach ($yahoo_result as $item) : ?> <div style='margin-bottom: 20px; padding: 30px; border: 1px solid #000; overflow:hidden;'> <div style='float: left;'><img src='<?php echo $item['img']; ?>'></div> <div style='float: left; padding: 20px;'> <div><?php echo $item['name']; ?></div> <div><a href='<?php echo $item['url']; ?>' target="_blank"><?php echo $item['url']; ?></a></div> <div><?php echo $item['price']; ?>円</div> </div> </div> <?php endforeach; ?> </body> </html> <?php function getYahooResult($keyword){ $baseurl = "http://shopping.yahooapis.jp/ShoppingWebService/V1/itemSearch"; $params = array(); $params["appid"] = "***"; $params["query"] = urlencode_rfc3986($keyword); $params["sort"] = urlencode_rfc3986("+price"); $params["affiliate_type"] = "vc"; $params["affiliate_id"] = urlencode_rfc3986("***"); $canonical_string = ""; foreach ($params as $k => $v){ $canonical_string .= "&" . $k . "=" . $v; } $canonical_string = substr($canonical_string, 1); $url = $baseurl . "?" . $canonical_string; // echo $url . "<br>"; $yahoo_xml = simplexml_load_string(@file_get_contents($url)); // print_r('<pre>'); // var_dump($yahoo_xml); // print_r('</pre>'); $items = array(); foreach($yahoo_xml->Result->Hit as $item){ $items[] = array( 'name' => (string)$item->Name, 'url' => (string)$item->Url, 'img' => (string)$item->Image->Medium, 'price' => (string)$item->Price, ); } var_dump($items); return $items; } function urlencode_rfc3986($str){ return str_replace("%7E", "~", rawurlencode($str)); } ?>