Jump to content

Recommended Posts

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:

 

exampleym9.png

 

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

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++;
      }
}

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.