| a | b | |
|---|
| 0 | + | <?php |
|---|
| 0 | + | define('API_KEY', 'YOUR API KEY'); |
|---|
| 0 | + | $base_url = "http://api.giantbomb.com/search/"; |
|---|
| 0 | + | if(isset($_POST['q'])) |
|---|
| 0 | + | { |
|---|
| 0 | + | $fields = array(); |
|---|
| 0 | + | $fields['query'] = $_POST['q']; |
|---|
| 0 | + | $fields['field_list'] = 'api_detail_url,resource_type,name,site_detail_url'; |
|---|
| 0 | + | $fields['api_key'] = API_KEY; |
|---|
| 0 | + | $url = $base_url . '?' . http_build_query($fields); |
|---|
| 0 | + | $data = file_get_contents($url); |
|---|
| 0 | + | $xml = simplexml_load_string($data); |
|---|
| 0 | + | } |
|---|
| 0 | + | ?> |
|---|
| 0 | + | <form method="post"> |
|---|
| 0 | + | <p> |
|---|
| 0 | + | <input type="text" name="q" id="search_q" /> |
|---|
| 0 | + | <input type="submit" value="Search" /> |
|---|
| 0 | + | </p> |
|---|
| 0 | + | </form> |
|---|
| 0 | + | <?php if (isset($xml)): ?> |
|---|
| 0 | + | <h2>Results:</h2> |
|---|
| 0 | + | <ul> |
|---|
| 0 | + | <?php foreach ($xml->results->children() as $item): ?> |
|---|
| 0 | + | <li class="<?php echo htmlentities($item->resource_type) ?>"> |
|---|
| 0 | + | <a href="<?php echo htmlentities($item->site_detail_url) ?>"><?php echo htmlentities($item->name) ?></a> |
|---|
| 0 | + | </li> |
|---|
| 0 | + | <?php endforeach; ?> |
|---|
| 0 | + | </ul> |
|---|
| 0 | + | <?php endif ?> |
|---|
| ... | |
|---|