Page 1 of 2

Displaying echo Outside PHP Script

Posted: Wed Jun 23, 2010 1:00 pm
by jonathantheaker
Hello,

I have a script I'm using to pull users highscores off of a MMORPG's website, sadly I'm having problems displaying the returned info where I need it to be displayed.

I'm wanting to show the returned info in its respective cell in the table, but when I try to echo the info in each cell it just dosent want to show. could anyone tell me what I'm doing wrong.

Here is my code without my messed up php echos in the table cells:

Code: Select all

<?php
function showInfo() {
    $user = $_GET['user'];
    $file = @file_get_contents('http://hiscore.runescape.com/index_lite.ws?player=' . $user);
    $explode = explode("\n", $file);
    $implode = implode(",", $explode);
    $stats = explode(",", $implode);
    echo '<b>' . $user . '</b>' . '<br>';
    echo 'Overall Rank: ' . $stats[0] . '<br>';
    echo 'Overall Level: ' . $stats[1] . '<br>';
    echo 'Overall Xp: ' . $stats[2] . '<br>';
    echo 'Attack Rank: ' . $stats[3] . '<br>';
    echo 'Attack Level: ' . $stats[4] . '<br>';
    echo 'Attack Xp: ' . $stats[5] . '<br>';
    echo 'Defence Rank: ' . $stats[6] . '<br>';
    echo 'Defence Level: ' . $stats[7] . '<br>';
    echo 'Defence Xp: ' . $stats[8] . '<br>';
    echo 'Strength Rank: ' . $stats[9] . '<br>';
    echo 'Strength Level: ' . $stats[10] . '<br>';
    echo 'Strength Xp: ' . $stats[11] . '<br>';
    echo 'Constitution Rank: ' . $stats[12] . '<br>';
    echo 'Constitution Level: ' . $stats[13] . '<br>';
    echo 'Constitution Xp: ' . $stats[14] . '<br>';
    echo 'Ranged Rank: ' . $stats[15] . '<br>';
    echo 'Ranged Level: ' . $stats[16] . '<br>';
    echo 'Ranged Xp: ' . $stats[17] . '<br>';
    echo 'Prayer Rank: ' . $stats[18] . '<br>';
    echo 'Prayer Level: ' . $stats[19] . '<br>';
    echo 'Prayer Xp: ' . $stats[20] . '<br>';
    echo 'Magic Rank: ' . $stats[21] . '<br>';
    echo 'Magic Level: ' . $stats[22] . '<br>';
    echo 'Magic Xp: ' . $stats[23] . '<br>';
    echo 'Cooking Rank: ' . $stats[24] . '<br>';
    echo 'Cooking Level: ' . $stats[25] . '<br>';
    echo 'Cooking Xp: ' . $stats[26] . '<br>';
    echo 'Woodcutting Rank: ' . $stats[27] . '<br>';
    echo 'Woodcutting Level: ' . $stats[28] . '<br>';
    echo 'Woodcutting Xp: ' . $stats[29] . '<br>';
    echo 'Fletching Rank: ' . $stats[30] . '<br>';
    echo 'Fletching Level: ' . $stats[31] . '<br>';
    echo 'Fletching Xp: ' . $stats[31] . '<br>';
    echo 'Fishing Rank: ' . $stats[33] . '<br>';
    echo 'Fishing Level: ' . $stats[34] . '<br>';
    echo 'Fishing Xp: ' . $stats[35] . '<br>';
    echo 'Firemaking Rank: ' . $stats[36] . '<br>';
    echo 'Firemaking Level: ' . $stats[37] . '<br>';
    echo 'Firemaking Xp: ' . $stats[38] . '<br>';
    echo 'Crafting Rank: ' . $stats[39] . '<br>';
    echo 'Crafting Level: ' . $stats[40] . '<br>';
    echo 'Crafting Xp: ' . $stats[41] . '<br>';
    echo 'Smithing Rank: ' . $stats[42] . '<br>';
    echo 'Smithing Level: ' . $stats[43] . '<br>';
    echo 'Smithing Xp: ' . $stats[44] . '<br>';
    echo 'Mining Rank: ' . $stats[45] . '<br>';
    echo 'Mining Level: ' . $stats[46] . '<br>';
    echo 'Mining Xp: ' . $stats[47] . '<br>';
    echo 'Herblore Rank: ' . $stats[48] . '<br>';
    echo 'Herblore Level: ' . $stats[49] . '<br>';
    echo 'Herblore Xp: ' . $stats[50] . '<br>';
    echo 'Agility Rank: ' . $stats[51] . '<br>';
    echo 'Agility Level: ' . $stats[52] . '<br>';
    echo 'Agility Xp: ' . $stats[53] . '<br>';
    echo 'Thieving Rank: ' . $stats[54] . '<br>';
    echo 'Thieving Level: ' . $stats[55] . '<br>';
    echo 'Thieving Xp: ' . $stats[56] . '<br>';
    echo 'Slayer Rank: ' . $stats[57] . '<br>';
    echo 'Slayer Level: ' . $stats[58] . '<br>';
    echo 'Slayer Xp: ' . $stats[59] . '<br>';
    echo 'Farming Rank: ' . $stats[60] . '<br>';
    echo 'Farming Level: ' . $stats[61] . '<br>';
    echo 'Farming Xp: ' . $stats[62] . '<br>';
    echo 'Runecrafting Rank: ' . $stats[63] . '<br>';
    echo 'Runecrafting Level: ' . $stats[64] . '<br>';
    echo 'Runecrafting Xp: ' . $stats[65] . '<br>';
    echo 'Hunter Rank: ' . $stats[66] . '<br>';
    echo 'Hunter Level: ' . $stats[67] . '<br>';
    echo 'Hunter Xp: ' . $stats[68] . '<br>';
    echo 'Construction Rank: ' . $stats[69] . '<br>';
    echo 'Construction Level: ' . $stats[70] . '<br>';
    echo 'Construction Xp: ' . $stats[71] . '<br>';
    echo 'Summoning Rank: ' . $stats[72] . '<br>';
    echo 'Summoning Level: ' . $stats[73] . '<br>';
    echo 'Summoning Xp: ' . $stats[74] . '<br>';
    echo 'Dungeoneering Rank: ' . $stats[75] . '<br>';
    echo 'Dungeoneering Level: ' . $stats[76] . '<br>';
    echo 'Dungeoneering Xp: ' . $stats[77] . '<br>';
}

if(isset($_GET['submit'])) {
    echo showInfo();
}
?> 

<table class="tablemain">
	<tr>
		<td class="mainheadercell" colspan="4">:: Hintscape High Scores ::</td>
	</tr>
	<tr>
		<td class="headercells">Skill</td>
		<td class="headercells">Rank</td>
		<td class="headercells">Level</td>
		<td class="headercells">Xp</td>
	</tr>
	<tr>
		<td class="cellmain">Overall</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Attack</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Defence</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Strength</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Constitution</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Ranged</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Prayer</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Magic</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Cooking</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Woodcutting</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Fletching</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Fishing</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Firemaking</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Crafting</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Smithing</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Mining</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">&nbsp;Herblore</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Agility</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Thieving</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Slayer</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Farming</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Runecrafting</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Hunter</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Construction</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Summoning</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	<tr>
		<td class="cellmain">Dungeoneering</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
		<td class="cellmain">&nbsp;</td>
	</tr>
	</table>
A working example can be found here = http://www.hintscape.net/0.php?user=Fre ... mit=Search

Any help would be great!
Regards
Jonathan

Re: Displaying echo Outside PHP Script

Posted: Wed Jun 23, 2010 1:53 pm
by jonathantheaker
I am trying putting the table within the code but that dosent seam to be working either...

Re: Displaying echo Outside PHP Script

Posted: Wed Jun 23, 2010 2:22 pm
by AbraCadaver
jonathantheaker wrote:I am trying putting the table within the code but that dosent seam to be working either...
Even though it doesn't make much sense, you've done a lot of work, so here's a start:

Code: Select all

<table class="tablemain">
	<tr>
		<td class="mainheadercell" colspan="4">:: Hintscape High Scores ::</td>
	</tr>
	<tr>
		<td class="headercells">Skill</td>
		<td class="headercells">Rank</td>
		<td class="headercells">Level</td>
		<td class="headercells">Xp</td>
	</tr>
<?php

$user = $_GET['user'];
$lines = file('http://hiscore.runescape.com/index_lite.ws?player=' . $user, FILE_IGNORE_NEW_LINES);
$headings = array('Overall', 'Attack'); //etc... you need to add the rest
		
$i = 0;
foreach($lines as $line) {
	$parts = explode(',', $line);
	echo '<tr>'
			.'<td class="cellmain">' . $headings[$i] . '</td>'
			.'<td class="cellmain">' . $parts[0] . '</td>'
			.'<td class="cellmain">' . $parts[1] . '</td>'
			.'<td class="cellmain">' . $parts[2] . '</td>'
	.'</tr>';
	$i++;
}

?>
</table>

Re: Displaying echo Outside PHP Script

Posted: Wed Jun 23, 2010 3:00 pm
by jonathantheaker
Hey, thanks for helping!

I have added in the other labels in to the array but the last ten wont display corectly, they dont have three lots of numbers returned by the script, if possible im trying to get it to display like this example http://services.runescape.com/m=hiscore ... redmcgarry the last ten rows need different headers. is this possible?

Heres the code so far

Code: Select all

<form action="" method="GET">
Please enter a username: <br>
    <input type="text" name="user" /> <br>
    <input type="submit" value="Search" name="submit" /> <br>
</form>
<table class="tablemain">
        <tr>
                <td class="mainheadercell" colspan="4">:: Hintscape High Scores ::</td>
        </tr>
        <tr>
                <td class="headercells">Skill</td>
                <td class="headercells">Rank</td>
                <td class="headercells">Level</td>
                <td class="headercells">Xp</td>
        </tr>
<?php

$user = $_GET['user'];
$lines = file('http://hiscore.runescape.com/index_lite.ws?player=' . $user, FILE_IGNORE_NEW_LINES);
$headings = array('Overall', 'Attack', 'Defence', 'Strength', 'Constitution', 'Ranged', 'Prayer', 'Magic', 'Cooking', 'Woodcutting', 'Fletching', 'Fishing', 'Firemaking', 'Crafting', 'Smithing', 'Mining', 'Herblore', 'Agility', 'Thieving', 'Slayer', 'Farming', 'Runecrafting', 'Hunter', 'Construction', 'Summoning', 'Dungeoneering', 'Overall', 'Attack', 'Defence', 'Strength', 'Constitution', 'Ranged', 'Prayer', 'Magic', 'Cooking', 'Woodcutting', 'Fletching', 'Fishing', 'Firemaking', 'Crafting', 'Smithing', 'Mining', 'Herblore', 'Agility', 'Thieving', 'Slayer', 'Farming', 'Runecrafting', 'Hunter', 'Construction', 'Summoning', 'Dungeoneering', 'Duel Tournament', 'Bounty Hunters', 'Bounty Hunter Rogues', 'Fist of Guthix', 'Mobilising Armies', 'B.A Attackers', 'B.A Defenders', 'B.A Collectors', 'B.A Healers', 'Castle Wars Games'); //etc... you need to add the rest
                
$i = 0;
foreach($lines as $line) {
        $parts = explode(',', $line);
        echo '<tr>'
                        .'<td class="cellmain">' . $headings[$i] . '</td>'
                        .'<td class="cellmain">' . $parts[0] . '</td>'
                        .'<td class="cellmain">' . $parts[1] . '</td>'
                        .'<td class="cellmain">' . $parts[2] . '</td>'
        .'</tr>';
        $i++;
}

?>
And heres a working example http://www.hintscape.net/2.php?user=Fre ... mit=Search

Re: Displaying echo Outside PHP Script

Posted: Wed Jun 23, 2010 3:58 pm
by AbraCadaver
This should do it. There are better ways maybe, but using the existing code:

Code: Select all

$lines = file('http://hiscore.runescape.com/index_lite.ws?player=' . $user, FILE_IGNORE_NEW_LINES);

$skills = array('Overall', 'Attack', 'Defence', 'Strength', 'Constitution', 'Ranged', 'Prayer', 'Magic', 'Cooking', 'Woodcutting', 'Fletching', 'Fishing', 'Firemaking', 'Crafting', 'Smithing', 'Mining', 'Herblore', 'Agility', 'Thieving', 'Slayer', 'Farming', 'Runecrafting', 'Hunter', 'Construction', 'Summoning', 'Dungeoneering', 'Overall', 'Attack', 'Defence', 'Strength', 'Constitution', 'Ranged', 'Prayer', 'Magic', 'Cooking', 'Woodcutting', 'Fletching', 'Fishing', 'Firemaking', 'Crafting', 'Smithing', 'Mining', 'Herblore', 'Agility', 'Thieving', 'Slayer', 'Farming', 'Runecrafting', 'Hunter', 'Construction', 'Summoning', 'Dungeoneering');

$activities = array('Duel Tournament', 'Bounty Hunters', 'Bounty Hunter Rogues', 'Fist of Guthix', 'Mobilising Armies', 'B.A Attackers', 'B.A Defenders', 'B.A Collectors', 'B.A Healers', 'Castle Wars Games');

//table and headings
$i = 0;
foreach($skills as $skill) {
	$parts = explode(',', $line[$i]);
	echo '<tr>'
			.'<td class="cellmain">' . $skill . '</td>'
			.'<td class="cellmain">' . $parts[0] . '</td>'
			.'<td class="cellmain">' . $parts[1] . '</td>'
			.'<td class="cellmain">' . $parts[2] . '</td>'
			.'</tr>';
	$i++;
}
//end table

//table and headings
foreach($activities as $activity) {
	$parts = explode(',', $line[$i]);
	echo '<tr>'
			.'<td class="cellmain">' . $activity . '</td>'
			.'<td class="cellmain">' . $parts[0] . '</td>'
			.'<td class="cellmain">' . $parts[1] . '</td>'
			.'</tr>';
	$i++;
}
//end table

Re: Displaying echo Outside PHP Script

Posted: Wed Jun 23, 2010 4:23 pm
by jonathantheaker
Ok so ive implemented the new code and assed in the echos for the tables but its having problems displaying the number strings.

Here is the code so far:

Code: Select all

<form action="" method="GET">
Please enter a username: <br>
    <input type="text" name="user" /> <br>
    <input type="submit" value="Search" name="submit" /> <br>
</form>
<?php
$user = $_GET['user'];
$lines = file('http://hiscore.runescape.com/index_lite.ws?player=' . $user, FILE_IGNORE_NEW_LINES);

$skills = array('Overall', 'Attack', 'Defence', 'Strength', 'Constitution', 'Ranged', 'Prayer', 'Magic', 'Cooking', 'Woodcutting', 'Fletching', 'Fishing', 'Firemaking', 'Crafting', 'Smithing', 'Mining', 'Herblore', 'Agility', 'Thieving', 'Slayer', 'Farming', 'Runecrafting', 'Hunter', 'Construction', 'Summoning', 'Dungeoneering', 'Overall', 'Attack', 'Defence', 'Strength', 'Constitution', 'Ranged', 'Prayer', 'Magic', 'Cooking', 'Woodcutting', 'Fletching', 'Fishing', 'Firemaking', 'Crafting', 'Smithing', 'Mining', 'Herblore', 'Agility', 'Thieving', 'Slayer', 'Farming', 'Runecrafting', 'Hunter', 'Construction', 'Summoning', 'Dungeoneering');

$activities = array('Duel Tournament', 'Bounty Hunters', 'Bounty Hunter Rogues', 'Fist of Guthix', 'Mobilising Armies', 'B.A Attackers', 'B.A Defenders', 'B.A Collectors', 'B.A Healers', 'Castle Wars Games');

        echo '<table class="tablemain">'
                        .'<tr>'
                        .'<td class="mainheadercell" colspan="4">:: Hintscape High Scores ::</td>'
                        .'</tr>'
                        .'<tr>'
                        .'<td class="headercells">Skill</td>'
                        .'<td class="headercells">Rank</td>'
                        .'<td class="headercells">Level</td>'
                        .'<td class="headercells">Xp</td>'
                        .'</tr>';
                        
$i = 0;
foreach($skills as $skill) {
        $parts = explode(',', $line[$i]);
        echo '<tr>'
                        .'<td class="cellmain">' . $skill . '</td>'
                        .'<td class="cellmain">' . $parts[0] . '</td>'
                        .'<td class="cellmain">' . $parts[1] . '</td>'
                        .'<td class="cellmain">' . $parts[2] . '</td>'
                        .'</tr>';
        $i++;
}
        echo '</table>';

        echo '<table class="tablemain">'
                        .'<tr>'
                        .'<td class="mainheadercell" colspan="3">Activities</td>'
                        .'</tr>'
                        .'<tr>'
                        .'<td class="headercells">Game</td>'
                        .'<td class="headercells">Rank</td>'
                        .'<td class="headercells">Score</td>'
                        .'</tr>';
                        
foreach($activities as $activity) {
        $parts = explode(',', $line[$i]);
        echo '<tr>'
                        .'<td class="cellmain">' . $activity . '</td>'
                        .'<td class="cellmain">' . $parts[0] . '</td>'
                        .'<td class="cellmain">' . $parts[1] . '</td>'
                        .'</tr>';
        $i++;
}
        echo '</table>';
?>
Here is the online example of the script so far: http://www.hintscape.net/test.php

Re: Displaying echo Outside PHP Script

Posted: Wed Jun 23, 2010 5:10 pm
by jonathantheaker
Ok so ive tried a few things but to no avail, im pretty sure its something to do with my table echos but everything i try des not help.

Re: Displaying echo Outside PHP Script

Posted: Wed Jun 23, 2010 5:48 pm
by AbraCadaver
My bad. I somehow doubled-up your $skills array, it should be:

Code: Select all

$skills = array('Overall', 'Attack', 'Defence', 'Strength', 'Constitution', 'Ranged', 'Prayer', 'Magic', 'Cooking', 'Woodcutting', 'Fletching', 'Fishing', 'Firemaking', 'Crafting', 'Smithing', 'Mining', 'Herblore', 'Agility', 'Thieving', 'Slayer', 'Farming', 'Runecrafting', 'Hunter', 'Construction', 'Summoning', 'Dungeoneering');
Also the two places where it says $line[$i] it should be $lines[$i]

Re: Displaying echo Outside PHP Script

Posted: Wed Jun 23, 2010 5:57 pm
by jonathantheaker
Oh that's brilliant, just about there now.

Example of working script online:
http://www.hintscape.net/test.php?user= ... mit=Search

Now i need to work out how to change the "-1" results (Which means "Not ranked") to say "Not Ranked", add commas to the returned number strings and have the table hidden until the form is processed, think i know how to do the latter, ill give it a bash but ive got some reading to do about the other two.

Here is the working code so far:

Code: Select all

<form action="" method="GET">
Please enter a username: <br>
    <input type="text" name="user" /> <br>
    <input type="submit" value="Search" name="submit" /> <br>
</form>
<?php

$user = $_GET['user'];
$lines = file('http://hiscore.runescape.com/index_lite.ws?player=' . $user, FILE_IGNORE_NEW_LINES);

$skills = array('Overall', 'Attack', 'Defence', 'Strength', 'Constitution', 'Ranged', 'Prayer', 'Magic', 'Cooking', 'Woodcutting', 'Fletching', 'Fishing', 'Firemaking', 'Crafting', 'Smithing', 'Mining', 'Herblore', 'Agility', 'Thieving', 'Slayer', 'Farming', 'Runecrafting', 'Hunter', 'Construction', 'Summoning', 'Dungeoneering');

$activities = array('Duel Tournament', 'Bounty Hunters', 'Bounty Hunter Rogues', 'Fist of Guthix', 'Mobilising Armies', 'B.A Attackers', 'B.A Defenders', 'B.A Collectors', 'B.A Healers', 'Castle Wars Games');

        echo '<table class="tablemain">'
                        .'<tr>'
                        .'<td class="mainheadercell" colspan="4">:: Hintscape High Scores ::</td>'
                        .'</tr>'
                        .'<tr>'
                        .'<td class="headercells">Skill</td>'
                        .'<td class="headercells">Rank</td>'
                        .'<td class="headercells">Level</td>'
                        .'<td class="headercells">Xp</td>'
                        .'</tr>';
                        
$i = 0;
foreach($skills as $skill) {
        $parts = explode(',', $lines[$i]);
        echo '<tr>'
                        .'<td class="cellmain">' . $skill . '</td>'
                        .'<td class="cellmain">' . $parts[0] . '</td>'
                        .'<td class="cellmain">' . $parts[1] . '</td>'
                        .'<td class="cellmain">' . $parts[2] . '</td>'
                        .'</tr>';
        $i++;
}
        echo '</table>';

        echo '<table class="tablemain">'
                        .'<tr>'
                        .'<td class="mainheadercell" colspan="3">Activities</td>'
                        .'</tr>'
                        .'<tr>'
                        .'<td class="headercells">Game</td>'
                        .'<td class="headercells">Rank</td>'
                        .'<td class="headercells">Score</td>'
                        .'</tr>';
                        
foreach($activities as $activity) {
        $parts = explode(',', $lines[$i]);
        echo '<tr>'
                        .'<td class="cellmain">' . $activity . '</td>'
                        .'<td class="cellmain">' . $parts[0] . '</td>'
                        .'<td class="cellmain">' . $parts[1] . '</td>'
                        .'</tr>';
        $i++;
}
        echo '</table>';
?>
Thanks for all of the help so far!

Re: Displaying echo Outside PHP Script

Posted: Wed Jun 23, 2010 6:23 pm
by jonathantheaker
Ok so i have managed to add commas to the number strings and change the "-1" results to say "Not Ranked", just working on hiding the table until the form is processed.

Re: Displaying echo Outside PHP Script

Posted: Wed Jun 23, 2010 7:09 pm
by jonathantheaker
I came up with "$lines = str_replace('-1','Not Ranked',$lines);" to replace the returned -1's with the words "Not Ranked" but when i use it with "number_format()" to add commas to my returned number strings the returned -1's are replaced with 0's instead of "Not Ranked", when i remove the "number_format()" it does replace the -1's with "not Ranked" but i obviously loose my much needed commas, and if i remove "$lines = str_replace('-1','Not Ranked',$lines);" i have commas but no "Not Ranked". There must be a way for me to have my cake and eat it.

Heres the working script so far:
http://services.hintscape.net/highscore ... mit=Lookup

Heres the code so far:

Code: Select all

				<?php

$user = $_GET['user'];
$lines = file('http://hiscore.runescape.com/index_lite.ws?player=' . $user, FILE_IGNORE_NEW_LINES);

$lines = str_replace('-1','Not Ranked',$lines);

$skills = array('Overall', 'Attack', 'Defence', 'Strength', 'Constitution', 'Ranged', 'Prayer', 'Magic', 'Cooking', 'Woodcutting', 'Fletching', 'Fishing', 'Firemaking', 'Crafting', 'Smithing', 'Mining', 'Herblore', 'Agility', 'Thieving', 'Slayer', 'Farming', 'Runecrafting', 'Hunter', 'Construction', 'Summoning', 'Dungeoneering');

$activities = array('Duel Tournament', 'Bounty Hunters', 'Bounty Hunter Rogues', 'Fist of Guthix', 'Mobilising Armies', 'B.A Attackers', 'B.A Defenders', 'B.A Collectors', 'B.A Healers', 'Castle Wars Games');

        echo '<table class="tablemain">'
                        .'<tr>'
                        .'<td class="mainheadercell" colspan="4">:: Hintscapes RuneScape High Scores ::</td>'
                        .'</tr>'
                        .'<tr>'
                        .'<td class="headercells">Skill</td>'
                        .'<td class="headercells">Rank</td>'
                        .'<td class="headercells">Level</td>'
                        .'<td class="headercells">Xp</td>'
                        .'</tr>';

$i = 0;
foreach($skills as $skill) {
        $parts = explode(',', $lines[$i]);
        echo '<tr>'
                        .'<td class="cellmain">' . $skill . '</td>'
                        .'<td class="cellmain">' . number_format($parts[0]) . '</td>'
                        .'<td class="cellmain">' . number_format($parts[1]) . '</td>'
                        .'<td class="cellmain">' . number_format($parts[2]) . '</td>'
                        .'</tr>';
        $i++;
}
        echo '</table><br>';

        echo '<table class="tablemain">'
                        .'<tr>'
                        .'<td class="mainheadercell" colspan="3">:: Activities ::</td>'
                        .'</tr>'
                        .'<tr>'
                        .'<td class="headercells">Game</td>'
                        .'<td class="headercells">Rank</td>'
                        .'<td class="headercells">Score</td>'
                        .'</tr>';
                        
foreach($activities as $activity) {
        $parts = explode(',', $lines[$i]);
        echo '<tr>'
                        .'<td class="cellmain">' . $activity . '</td>'
                        .'<td class="cellmain">' . number_format($parts[0]) . '</td>'
                        .'<td class="cellmain">' . number_format($parts[1]) . '</td>'
                        .'</tr>';
        $i++;
}
        echo '</table><br>';
?>
Any tips would be much apriciated as my brain is hurting.

Re: Displaying echo Outside PHP Script

Posted: Thu Jun 24, 2010 10:44 am
by AbraCadaver
I would remove the number_format() from the echos and add this before the str_replace():

Code: Select all

$lines = array_map('number_format', $lines);

Re: Displaying echo Outside PHP Script

Posted: Thu Jun 24, 2010 12:57 pm
by jonathantheaker
Hmm, i have tried you sugestion and it seams to still give me the same problem but also messes up all of the "level" numbers, the max level achievable is 99 and im now getting numbers up to 843 showing. Also its only putting the "not Ranked" in the "Rank" columns.

Working script so far:
http://services.hintscape.net/highscore ... mit=Lookup

Code So Far

Code: Select all

<?php

$user = $_GET['user'];
$lines = file('http://hiscore.runescape.com/index_lite.ws?player=' . $user, FILE_IGNORE_NEW_LINES);

$lines = array_map('number_format', $lines);

$lines = str_replace('-1', 'Not Ranked', $lines);

$skills = array('Overall', 'Attack', 'Defence', 'Strength', 'Constitution', 'Ranged', 'Prayer', 'Magic', 'Cooking', 'Woodcutting', 'Fletching', 'Fishing', 'Firemaking', 'Crafting', 'Smithing', 'Mining', 'Herblore', 'Agility', 'Thieving', 'Slayer', 'Farming', 'Runecrafting', 'Hunter', 'Construction', 'Summoning', 'Dungeoneering');

$activities = array('Duel Tournament', 'Bounty Hunters', 'Bounty Hunter Rogues', 'Fist of Guthix', 'Mobilising Armies', 'B.A Attackers', 'B.A Defenders', 'B.A Collectors', 'B.A Healers', 'Castle Wars Games');

        echo '<table class="tablemain">'
                        .'<tr>'
                        .'<td class="mainheadercell" colspan="4">Skill Hiscores - ' . $user . ' </td>'
                        .'</tr>'
                        .'<tr>'
                        .'<td class="headercells">Skill</td>'
                        .'<td class="headercells">Rank</td>'
                        .'<td class="headercells">Level</td>'
                        .'<td class="headercells">Xp</td>'
                        .'</tr>';

$i = 0;
foreach($skills as $skill) {
        $parts = explode(',', $lines[$i]);
        echo '<tr>'
                        .'<td class="cellmain">' . $skill . '</td>'
                        .'<td class="cellmain">' . $parts[0] . '</td>'
                        .'<td class="cellmain">' . $parts[1] . '</td>'
                        .'<td class="cellmain">' . $parts[2] . '</td>'
                        .'</tr>';
        $i++;
}
        echo '</table><br>';

        echo '<table class="tablemain">'
                        .'<tr>'
                        .'<td class="mainheadercell" colspan="3">Activity Hiscores - ' . $user . ' </td>'
                        .'</tr>'
                        .'<tr>'
                        .'<td class="headercells">Game</td>'
                        .'<td class="headercells">Rank</td>'
                        .'<td class="headercells">Score</td>'
                        .'</tr>';
                        
foreach($activities as $activity) {
        $parts = explode(',', $lines[$i]);
        echo '<tr>'
                        .'<td class="cellmain">' . $activity . '</td>'
                        .'<td class="cellmain">' . $parts[0] . '</td>'
                        .'<td class="cellmain">' . $parts[1] . '</td>'
                        .'</tr>';
        $i++;
}
        echo '</table><br>';
?>


Re: Displaying echo Outside PHP Script

Posted: Thu Jun 24, 2010 1:37 pm
by AbraCadaver
Sorry, I was tired and hadn't tested it. Move the str_replace() and the array_map() into each loop after the explode():

Code: Select all

$parts = explode(',', $lines[$i]);
$parts = array_map('number_format',  $parts);
$parts = str_replace('-1', 'Not Ranked', $parts);

Re: Displaying echo Outside PHP Script

Posted: Thu Jun 24, 2010 6:38 pm
by jonathantheaker
Brilliant, thats working perfectly.

Working Script!
http://services.hintscape.net/highscores/

I'm going to be a pest now, I'm wanting to place a 16 x 16 px image just in front of each skill/activity name we have stored in the $skills array and the $activities array.

At a guess I would think I have to store the image URL's in an array but I wouldn't know how to have the script actually insert them. Do you have any pointers on where to begin?

Script So Far:

Code: Select all

<?php

$user = $_GET['user'];
$lines = file('http://hiscore.runescape.com/index_lite.ws?player=' . $user, FILE_IGNORE_NEW_LINES);

$skills = array('Overall', 'Attack', 'Defence', 'Strength', 'Constitution', 'Ranged', 'Prayer', 'Magic', 'Cooking', 'Woodcutting', 'Fletching', 'Fishing', 'Firemaking', 'Crafting', 'Smithing', 'Mining', 'Herblore', 'Agility', 'Thieving', 'Slayer', 'Farming', 'Runecrafting', 'Hunter', 'Construction', 'Summoning', 'Dungeoneering');

$activities = array('Duel Tournament', 'Bounty Hunters', 'Bounty Hunter Rogues', 'Fist of Guthix', 'Mobilising Armies', 'B.A Attackers', 'B.A Defenders', 'B.A Collectors', 'B.A Healers', 'Castle Wars Games');

        echo '<table class="tablemain">'
                        .'<tr>'
                        .'<td class="mainheadercell" colspan="4">Skill Hiscores - ' . $user . ' </td>'
                        .'</tr>'
                        .'<tr>'
                        .'<td class="headercells">Skill</td>'
                        .'<td class="headercells">Rank</td>'
                        .'<td class="headercells">Level</td>'
                        .'<td class="headercells">Xp</td>'
                        .'</tr>';

$i = 0;
foreach($skills as $skill) {
        $parts = explode(',', $lines[$i]);
		$parts = array_map('number_format',  $parts);
		$parts = str_replace('-1', '--', $parts);
        echo '<tr>'
                        .'<td class="cellmain">' . $skill . '</td>'
                        .'<td class="cellmain">' . $parts[0] . '</td>'
                        .'<td class="cellmain">' . $parts[1] . '</td>'
                        .'<td class="cellmain">' . $parts[2] . '</td>'
                        .'</tr>';
        $i++;
}
        echo '</table><br>';

        echo '<table class="tablemain">'
                        .'<tr>'
                        .'<td class="mainheadercell" colspan="3">Activity Hiscores - ' . $user . ' </td>'
                        .'</tr>'
                        .'<tr>'
                        .'<td class="headercells">Game</td>'
                        .'<td class="headercells">Rank</td>'
                        .'<td class="headercells">Score</td>'
                        .'</tr>';
                        
foreach($activities as $activity) {
        $parts = explode(',', $lines[$i]);
		$parts = array_map('number_format',  $parts);
		$parts = str_replace('-1', '--', $parts);
        echo '<tr>'
                        .'<td class="cellmain">' . $activity . '</td>'
                        .'<td class="cellmain">' . $parts[0] . '</td>'
                        .'<td class="cellmain">' . $parts[1] . '</td>'
                        .'</tr>';
        $i++;
}
        echo '</table><br>';
?>