Jump to content

[SOLVED] Need yet more help with this script


prime

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.