Displaying echo Outside PHP Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Displaying echo Outside PHP Script

Post by AbraCadaver »

At its simplest you would have images named just like the skill except with an extension like .gif or whatever, so 'Attack.gif'. Then you can just echo an img tag with the src set to $parts[0].'.gif'
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
jonathantheaker
Forum Newbie
Posts: 14
Joined: Fri Apr 23, 2010 2:48 pm
Location: Huddersfield, West Yorkshire, England, United Kingdom, Earth.

Re: Displaying echo Outside PHP Script

Post by jonathantheaker »

Thanks for that its worked a treat!

Finnished and working Code:

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"><img border="0" src="' . strtolower($skill) . '.gif"><br>' . $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"><img border="0" src="' . strtolower($activity) . '.gif"><br>' . $activity . '</td>'
                        .'<td class="cellmain">' . $parts[0] . '</td>'
                        .'<td class="cellmain">' . $parts[1] . '</td>'
                        .'</tr>';
        $i++;
}
        echo '</table><br>';
?>
URL to working script (Use username HSA Jay if testing): http://services.hintscape.net/highscores/

So id lke to say a huge thank you to AbraCadaver for all of his help. I hope someone else may be able to make use of this code or parts of it.

Thanks again!
Post Reply