<?php /** * @see http://code.google.com/intl/ja/apis/ajaxsearch/documentation/#fonje */ function escape($str) { return htmlspecialchars($str, ENT_QUOTES); } $keyword = $_GET['keyword']; if ($keyword) { if (is_numeric($_GET['pageNo'])) { $pageNo = $_GET['pageNo']; } else { $pageNo = 0; } $url = 'http://ajax.googleapis.com/ajax/services/search/web?'; $url .= http_build_query(array( 'q' => $keyword, 'v' => '1.0', 'rsz' => 'large', 'hl' => 'ja', 'start' => $pageNo * 8, )); $json = json_decode(file_get_contents($url)); if ($json->responseData->results) { foreach ($json->responseData->results as $page) { echo '<a href="' . $page->url . '">' . $page->title . '</a><br />'; } $pageNo++; $next = escape(http_build_query(compact('keyword', 'pageNo'))); echo '<a href="?' . $next . '">次へ >></a>'; } } ?> <form action="?"> <div> <input type="text" name="keyword" value="<?php echo escape($keyword) ?>" /> <input type="submit" value="検索" /> </div> </form>