Revision 363366303865 () - Diff

Link to this snippet: https://friendpaste.com/62Zi7sK2UPIYXPJKMZaAre
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
define('API_KEY', 'YOUR API KEY');
$base_url = "http://api.giantbomb.com/search/";
if(isset($_POST['q']))
{
$fields = array();
$fields['query'] = $_POST['q'];
$fields['field_list'] = 'api_detail_url,resource_type,name,site_detail_url';
$fields['api_key'] = API_KEY;
$url = $base_url . '?' . http_build_query($fields);
$data = file_get_contents($url);
$xml = simplexml_load_string($data);
}
?>
<form method="post">
<p>
<input type="text" name="q" id="search_q" />
<input type="submit" value="Search" />
</p>
</form>
<?php if (isset($xml)): ?>
<h2>Results:</h2>
<ul>
<?php foreach ($xml->results->children() as $item): ?>
<li class="<?php echo htmlentities($item->resource_type) ?>">
<a href="<?php echo htmlentities($item->site_detail_url) ?>"><?php echo htmlentities($item->name) ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endif ?>