<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Primary Games Arena API</title>
    <meta name="generator" content="TextMate http://macromates.com/">
    <meta name="author" content="John Johnston">
    <!-- Date: 2011-07-11 -->
    <style type="text/css" media="screen">
    .linkbox{background:#CCC;padding:4px;margin:10px;-moz-border-radius: 5px; -webkit-border-radius: 5px;width:240px;float:left;height:240px;overflow:hidden;text-align:center}
    .linkbox p{text-align:left;font-size:13px}
    .linkbox img {border:none}
    .linkbox button{float:right;}
    h4{padding:0px;margin:0px;}
</style>
</head>
<body>
<form action="" method="get" accept-charset="utf-8" >
Search: <input type="text" name="q" value="" id="q"> Year:  
    <select name="Year" id="Year">
        <option value="all">All</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
    </select>

 Subject: 
     <select name="Subject" id="Subject">
        <option value="all">All</option>
        <option value="Maths">Maths</option>
        <option value="English">English</option>
        <option value="Science">Science</option>
        <option value="RE">Religion</option>
        <option value="Music">Music</option>
        <option value="Spanish">Spanish</option>
        <option value="German">German</option>
        <option value="French">French</option>
        <option value="History">History</option>
        <option value="Geography">Geography</option>
        <option value="Design-and-Technology">Design-and-Technology</option>
        <option value="Art-and-Design">Art-and-Design</option>
        <option value="PSHE">PSHE</option>
    </select>

Game Type:
    <select name="gametype" id="gametype">
        <option value="all">All</option>
        <option value="Strategy">Strategy</option>
        <option value="Action">Action</option>
        <option value="Shooter">Shooter</option>
        <option value="Construction">Construction</option>
        <option value="Simulation">Simulation</option>
        <option value="Role play">Role play</option>
        <option value="Adventure">Adventure</option>
        <option value="Sport">Sport</option>
        <option value="Puzzle">Puzzle</option>
    </select>
        <p><input type="submit" value="Go &rarr;" ></p>
    </form>    
    <?php
 

 $ruri 
str_replace("/pg/pg.php","",$_SERVER['REQUEST_URI']);
 
if (
strlen($ruri)>3)
    {
 
        
$daurl="http://primarygamesarena.com/searchapi.php".$ruri;
         echo 
"<p>".$daurl."</p>";
        
$ch curl_init();
        
curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
        
curl_setopt($chCURLOPT_URL$daurl);
        
curl_setopt($chCURLOPT_VERBOSE1);
        
curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
curl_setopt($chCURLOPT_BINARYTRANSFER1);
         
curl_setopt($chCURLOPT_HTTP_VERSIONCURL_HTTP_VERSION_1_1);
 
        
$result curl_exec($ch);
        
$resultArray curl_getinfo($ch);

        
curl_close($ch);


        
$xml = new SimpleXmlElement($result);
 
        
$count 0;
            foreach (
$xml->game as $entry)
            {
                if(
$count <100)
                {
                
$title $entry->name;
                
$url $entry->url;
                
$description $entry->description;
                
$thumb $entry->thumbnail;
                
$title=urldecode($title);
                
$title=urldecode($title);
                
$description=urldecode($description);
                
$description=urldecode($description);
                
$description=substr($description,0,80);
                
$url=urldecode($url);
                
$url=urldecode($url);
                echo 
"<div class=\"linkbox\"><h4> <a href='$url'>$title</a></h4>";
                 echo 
"<a href='$url'><img src=\"$thumb\"></a>";
                echo 
"<p>$description</p></div>";
                
                
$count $count+1;
                }
            }

    }
?>
 </body>
</html>