Scripts

Runescape exchange calculator

Hoi allemaal, Ik heb een script gemaakt waarmee je prijzen van runescape mee kan bereken. Vragen en/of opmerkingen post ze alsjeblieft. Voorbeeld id's zijn 359 en 563

runescape-exchange-calculator
[code]<?php
//laat alle errors zien
ini_set('display_errors',1);
error_reporting(E_ALL);

//layout laden
include("top.php");

//checkt of het formulier in is gevult
if($_SERVER['REQUEST_METHOD'] == "POST" ) {
//checkt of de informatie correct is ingevult

$amount= array();
$amount= $_POST['amount'];
$id= array();
$id= $_POST['id'];
$price = 0;
$price2 = 0;

//Price checken en vermenigvuldigen met het amount
function getprice($id){
$begin = "<b>Market price:</b> ";
$eind = "</span>";
$maximale_delay = 5;
$site = "http://itemdb-rs.runescape.com/viewitem.ws?obj=".$id;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $site);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $maximale_delay);
if(curl_errno($ch))
{
    return 'EVDC';
}else{
$start = curl_exec($ch);
curl_close($ch);
if(strstr($start,$id)) {
$exploded = explode($begin,$start);
$exploded = explode($eind,$exploded[1]);
$result = str_replace('<br />','',nl2br($exploded[0]));
   return $result;
}else{
    return "EVID";
}
}
}
function image($id){
$result = '<img alt="&lsquo;'.$id.'&rsquo;" src="http://itemdb-rs.runescape.com/2669_obj_big.gif?id='.$id.'"></img>';
   return $result;
}
    echo'<h1>Exchange Calculator</h1>';
    for($i=0; $i < count($_POST['amount']); $i++)
  {
   if ($amount[$i]!='' and $id[$i]!=''){
       if (getprice($id[$i])== "EVID"){
   echo 'Het id &lsquo;'.$id[$i].'&rsquo; bestaat niet.<br />';
   }elseif(getprice($id[$i])== "EVDC"){
	   echo 'Het id mag alleen cijfers bevatten.<br />';
   }else{
   $price = $amount[$i] * getprice($id[$i]);
   $price2 = $price2 + $price;
   echo $amount[$i].'x'.image($id[$i]).'='.$price.'gp<br />';
   }
   }
   }
   echo '<br />Total price = '.$price2.'gp';
}else{
//het formulier

?>
<h1>Exchange Calculator</h1>
<form id="pricecheckform" name="pricecheckform" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<table width="100%"border="0">
  <tr>
      <td>Amount</td>
    <td>Id</td>
  </tr>
  <tr>
    <td><input type="text" name="amount[]" /></td>
    <td><input type="text" name="id[]" /></td>
  </tr>
  <tr>
    <td><input type="text" name="amount[]" /></td>
    <td><input type="text" name="id[]" /></td>
  </tr>
  <tr>
    <td><input type="text" name="amount[]" /></td>
    <td><input type="text" name="id[]" /></td>
  </tr>
  <tr>
    <td><input type="text" name="amount[]" /></td>
    <td><input type="text" name="id[]" /></td>
  </tr>
  <tr>
    <td><input type="text" name="amount[]" /></td>
    <td><input type="text" name="id[]" /></td>
  </tr>
  <tr>
    <td></td>
    <td><input name="calc" type="submit" value="Calculate" /></td>
  </tr>
</table>
</form>
<?php
}
include("end.php");
?> [/code]

Reacties

0
Nog geen reacties.