Im trying to write ELO RATING CALCULATOR in PHP but so far im not getting any right results.

Im trying to make it work like this javascript calculator

Calculate ELO difference from record or winning percentage

Where with team1 ELO and team2 ELO is 2000 and there result for this is:

won: 16

draw: 0

losser: -16

This is far what i did made from backend:

```
// my rating before the match
$team1 = 2000;
// rating opponent player
$team2 = 2000;
// my expected chance of winning (1 = 100% and 0 = 0%)
$result = 1 / (1 + 10 ^ (($team2 - $team1) / 400));
// 1 is for winning 0.5 draw and 0 loss
$won = 32 * (1.0 - $result);
////////////if draw////////////////////////////
$draw = 32 * ( 0.5 - $result);
////////////if lost////////////////////////////
$lost = 32 * ( 0.0 - $result);
echo"
won:<br>
$won<br>
draw: <br>
$draw<br>
losser:<br>
$lost<br><br><br>";
```

and result from my script is:

won: 29.0909090909

draw: 13.0909090909

losser: -2.90909090909

Im not sure where i am wrong.

Also i have code for this java but im not sure how to make it work same in just php using forms:

```
<script type="text/javascript">
function CalculateRatingChange()
{
var Elo1 = document.rating.elo1.value * 1;
var Elo2 = document.rating.elo2.value * 1;
var K = document.rating.K.value * 1;
var EloDifference = Elo2 - Elo1;
var percentage = 1 / ( 1 + Math.pow( 10, EloDifference / 400 ) );
var win = Math.round( K * ( 1 - percentage ) );
var draw = Math.round( K * ( .5 - percentage ) );
if (win > 0 ) win = "+" + win;
if (draw > 0 ) draw = "+" + draw;
document.ratingchange.win.value = win;
document.ratingchange.draw.value = draw;
document.ratingchange.loss.value = Math.round( K * ( 0 - percentage ) );
document.ratingchange.percent.value = Math.round( percentage * 100 ) + "%";
}
</script>
```

Any help will be greatfull.