Jump to content

error when i add two variables


rswildy

Recommended Posts

Hi.

<?php$contents = "";$handle = fopen("http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=". urlencode($_GET['username']),"r");if($handle){  while (!feof($handle))  {	$contents .= fread($handle, 8192);  }  fclose($handle);}function parse($skill_name){  global $contents;  $matches = array();  $pattern = "@<tr>\\s<td.*><img.*></td>\\s<td.*><a.*>\\s" . $skill_name . "\\s</a></td>\\s<td.*>([0-9,\\s]*)</td>\\s<td.*>([0-9,\\s]*)</td>\\s<td.*>([0-9,\\s]*)</td>\\s</tr>@imsU";  $match_found = preg_match($pattern, $contents, $matches);  $retval = array();  if ($match_found && $matches[1] != "")	$retval['rank'] = $matches[1];  else	$retval['rank'] = "--";  if ($match_found && $matches[2] != "")	$retval['level'] = $matches[2];  else	$retval['level'] = "--";  if ($match_found && $matches[3] != "")	$retval['xp'] = $matches[3];  else	$retval['xp'] = "--";  return $retval;}$target_lvl  = $_GET['target_lvl'] * 150 + $Woodcutting['xp'];$Woodcutting = parse("Woodcutting");echo "Rank: " . $Woodcutting['rank'] . "<br>";echo "Level: " . $Woodcutting['level'] . "<br>";echo "XP: " . $Woodcutting['xp'] . "<br>";echo "You need to cut " . $Woodcutting['level'] . " Yew trees. " . "<br />";echo "If you cut " . $_GET['target_lvl'] . " Yew trees you will have a total of " . $target_lvl. "xp." . "<br />";?>

The output of this code is everything shows fine except:

$target_lvl  = $_GET['target_lvl'] * 150 + $Woodcutting['xp'];

The problem with this line is the + $woodcutting['xp'] i think its because the numbers on the main code ['xp'] are formatted with commas' If someone could make it work then i would be happy.Thanks, Rswildy.

Link to comment
Share on other sites

My first question is, is the variable you use in the euqation a number or string? If its a string then use intval():

$variable = "1990";$equation = intval($variable)+1;print $equation;//Will print 1991

Also whats the + in front of $_GET['target_lvl'] ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...