rswildy Posted April 13, 2007 Share Posted April 13, 2007 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 More sharing options...
Xenon Design Posted April 13, 2007 Share Posted April 13, 2007 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 More sharing options...
rswildy Posted April 13, 2007 Author Share Posted April 13, 2007 + Is gone, Its a variable i guess. Link to comment Share on other sites More sharing options...
rswildy Posted April 14, 2007 Author Share Posted April 14, 2007 Still not fixed, Could anyone help? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 16, 2007 Share Posted April 16, 2007 If you want to remove commas from a string and convert it to a number: $num = floatval(str_replace(",", "", $str)); Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now