php-tool-box:google-ajax-search-api
文書の過去の版を表示しています。
PHPでGoogle AJAX Search APIを使うサンプル
サンプル
ソースコード
<?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)); 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>
php-tool-box/google-ajax-search-api.1266155080.txt.gz · 最終更新: 2010/02/14 22:44 by dgbadmin