prime Posted August 15, 2007 Share Posted August 15, 2007 I've been developing this script more: <html><head> <?php //include styles and javascript files include("../../../style_java_include.inc"); ?> </head><body bgcolor="black"> <?php $names = array( 'Overall:', 'Attack:', 'Defence:', 'Strength:', 'Hitpoints:', 'Ranged:', 'Prayer:', 'Magic:', 'Cooking:', 'Woodcutting:', 'Fletching:', 'Fishing:', 'Firemaking:', 'Crafting:', 'Smithing:', 'Mining:', 'Herblore:', 'Agility:', 'Thieving:', 'Slayer:', 'Farming:', 'Runecraft:', 'Hunter:', 'Construction:', ); $name = (isset($_POST['rsname']) && strlen($_POST['rsname']) > 0) ? $_POST['rsname'] : null; if($name != null) { $url = 'http://hiscore.runescape.com/index_lite.ws?player='.$name; $handle = @fopen($url, 'rb'); if($handle) { $contents = ''; while (!feof($handle)) { //while the file end isnt reached $contents .= fread($handle, 8192); } $contents = explode("\n", $contents); //split the content at linebreaks and put it into array $contents $i = 0; foreach($contents as $v) { $e = explode(',', $v); $skills[$i]['rank'] = number_format($e[0]); $skills[$i]['level'] = number_format($e[1]); $skills[$i]['xp'] = number_format($e[2]); $i++; } echo '<table border="0" bordercolor="red" align="center"> <tr> <td width="60"><b class="otkhead">Skill</b></td> <td width="40"><b class="otkhead">Level</b></td> <td width="50"><b class="otkhead">Rank</b></td> <td width="30"><b class="otkhead">XP</b></td> </tr>'; foreach($skills as $k => $v) { echo '<tr> <td><b class="otkskilltitle">'.$names[$k].'</b></td> <td>'; //lLevel Conditionals if($v['level'] <= '1') { echo '<b class="otkskills">N/A</b>'; } else { echo '<b class="otkskills">'.$v['level'].'</b>'; } echo '</td> <td>'; //Rank Conditionals if($v['rank'] < '1') { echo '<b class="otkskills">N/A</b>'; } else { echo '<b class="otkskills">'.$v['rank'].'</b>'; } echo '</td> <td>'; //XP Conditionals if($v['xp'] < '1') { echo '<b class="otkskills">N/A</b>'; } else { echo '<b class="otkskills">'.$v['xp'].'</b>'; } echo '</td> </tr>'; } echo '</table>'; } else { echo '<font color="white">Unable to find the user or open the page. Please make sure the username is correct or try again later.</font>'; } } ?> </body></html> It's actualy coming along great, I've just come across one brick wall, which I cant seem to find a solution for, actualy hell I'm not sure exactly why it's doing it in the first place. it seems to be creating an extra row of 0 values at the bottom after it should have stopped which my conditional is then turning into n/a's which is fine, but the data shouldn't be there in the first place for it to convert here's an image: see the bottom row of n/a's? thats what I need help with to remove or stop, the contruction row should be the final row full stop... any help would be greatly appreciated, thank you Quote Link to comment https://forums.phpfreaks.com/topic/64969-solved-need-yet-more-help-with-this-script/ Share on other sites More sharing options...
dbo Posted August 15, 2007 Share Posted August 15, 2007 It -might- be the extra comma at the end of your array list. Quote Link to comment https://forums.phpfreaks.com/topic/64969-solved-need-yet-more-help-with-this-script/#findComment-324226 Share on other sites More sharing options...
prime Posted August 15, 2007 Author Share Posted August 15, 2007 Unfortunately I've already tried removing the comma there to make it: 'Construction:' ); , still does it :-( I had thought of that myself it's probaly just a silly mistake I made somewhere but I cant find it Quote Link to comment https://forums.phpfreaks.com/topic/64969-solved-need-yet-more-help-with-this-script/#findComment-324229 Share on other sites More sharing options...
dbo Posted August 15, 2007 Share Posted August 15, 2007 When you loop through that content array try outputting the line number and the data. It could be that you have some empty record at the end of the file or something. Quote Link to comment https://forums.phpfreaks.com/topic/64969-solved-need-yet-more-help-with-this-script/#findComment-324231 Share on other sites More sharing options...
Fadion Posted August 15, 2007 Share Posted August 15, 2007 I tested the script locally and u got an empy value in the end of the array and two solutions may be: just removing the last array value: array_pop($contents); foreach($contents as $v) { ....... or by conditioning, to see if the value is not empty foreach($contents as $v) { if(strlen($v) > 1){ $e = explode(',', $v); $skills[$i]['rank'] = number_format($e[0]); $skills[$i]['level'] = number_format($e[1]); $skills[$i]['xp'] = number_format($e[2]); $i++; } } Quote Link to comment https://forums.phpfreaks.com/topic/64969-solved-need-yet-more-help-with-this-script/#findComment-324276 Share on other sites More sharing options...
prime Posted August 15, 2007 Author Share Posted August 15, 2007 yup that works great thank you Quote Link to comment https://forums.phpfreaks.com/topic/64969-solved-need-yet-more-help-with-this-script/#findComment-324315 Share on other sites More sharing options...
dbo Posted August 15, 2007 Share Posted August 15, 2007 Argh I knew it Quote Link to comment https://forums.phpfreaks.com/topic/64969-solved-need-yet-more-help-with-this-script/#findComment-324316 Share on other sites More sharing options...
prime Posted August 15, 2007 Author Share Posted August 15, 2007 yah I figured you were right when you said it, I just wasn't sure what to do. Im pretty much still a php nooby, learnign as fast as a I can though Quote Link to comment https://forums.phpfreaks.com/topic/64969-solved-need-yet-more-help-with-this-script/#findComment-324319 Share on other sites More sharing options...
dbo Posted August 15, 2007 Share Posted August 15, 2007 foreach($contents as $v) { $e = explode(',', $v); if( count($e) == 3 ) { $skills[$i]['rank'] = number_format($e[0]); $skills[$i]['level'] = number_format($e[1]); $skills[$i]['xp'] = number_format($e[2]); } ++$i; } Here's another solution I think should work. Quote Link to comment https://forums.phpfreaks.com/topic/64969-solved-need-yet-more-help-with-this-script/#findComment-324325 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.