[HELP] Parser

Everything PHP-related! Discuss scripts, host challenges, request a script, or just ask for plain old help.

Moderators: IRC Operators, Support Team

User avatar
Hobold
User
User
Posts: 60
Joined: Sun Feb 10, 2008 3:33 am
Location: Tubarão, Brazil
Contact:

[HELP] Parser

Postby Hobold » Sun Oct 05, 2008 1:23 pm

Hello.

I have just started with PHP and I can't get my parser to work properly. I supply the nick but it doesn't give me the answer.

Code: Select all

<?php
$skills = 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:", "Summoning:", "Dueling:", "Bounty Hunter:", "Bounty Hunter Rogue:", "Fist Of Guthix:");
$site = @file("http://hiscore.runescape.com/index_lite.ws?player=".$_GET['nick']);
$x = 0;
while ($x<=28) {
$y = explode(",", $site[$x]);
echo "$skills[$x] LEVEL: $y[1] EXP: $y[2] RANK: $y[0]";
echo "<p>";
$x++;
}
?>


Thanks in advance,
Hobold.
Image Image
User avatar
Hova
User
User
Posts: 656
Joined: Sat Oct 04, 2008 9:14 pm

Postby Hova » Sun Oct 05, 2008 1:46 pm

Learn for.

Try putting E^ALL on, I can't remember how.

edit: Spacing.. I thought that didn't look right.
Last edited by Hova on Sun Oct 05, 2008 4:53 pm, edited 1 time in total.
Image
[url=http://my.opera.com/tobylane/affiliate]Image
<Vivec> Don't mess with toby guys; he's a professional troll.[/url]
Srankie
User
User
Posts: 963
Joined: Thu Mar 01, 2007 7:16 pm
Location: #godscript #msl HOLLAND

Postby Srankie » Sun Oct 05, 2008 4:13 pm

Code: Select all

<?php
if (!isset($_GET['nick'])) {
    die("?nick=NICK");
}
$skills = 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:", "Summoning:", "Dueling:", "Bounty Hunter:",
    "Bounty Hunter Rogue:", "Fist Of Guthix:");
$site = @file("http://hiscore.runescape.com/index_lite.ws?player=" . $_GET['nick']);
for ($x = 0; $x <= 28; $x++) {
    $y = explode(",", $site[$x]);
    echo "{$skills[$x]} LEVEL: {$y[1]} EXP: {$y[2]} RANK: {$y[0]}<p>";
}
?>
Image
Image
Katlyn
User
User
Posts: 939
Joined: Mon Aug 28, 2006 9:12 pm
Location: London

Postby Katlyn » Sun Oct 05, 2008 5:29 pm

Hova wrote:Learn for.

Try putting E^ALL on, I can't remember how.

edit: Spacing.. I thought that didn't look right.


WHILE is faster than FOR. Your script is basically all correct, you just need to change

Code: Select all

echo "$skills[$x] LEVEL: $y[1] EXP: $y[2] RANK: $y[0]";


to

Code: Select all

echo "$skills[$x] LEVEL: " . $y[1] . " EXP: " . $y[2] . " RANK: " . $y[0] ."";


Arrays don't work inside those quotes.
User avatar
Hobold
User
User
Posts: 60
Joined: Sun Feb 10, 2008 3:33 am
Location: Tubarão, Brazil
Contact:

Postby Hobold » Sun Oct 05, 2008 8:38 pm

Thanks everybody, already fixed it.

Code: Select all

<?php
$skills = 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:", "Summoning:", "Dueling:", "Bounty Hunter:", "Bounty Hunter Rogue:", "Fist Of Guthix:");
$site = file("http://hiscore.runescape.com/index_lite.ws?player=".$_GET['nick']);
$x = 0;
while ($x<=28) {
$y = explode(",", $site[$x]);
if ($y[3] != false) {
echo "$skills[$x] LEVEL: $y[1] EXP: $y[2] RANK: $y[0]";
}
else {
echo "$skills[$x] LEVEL: $y[1] EXP: $y[2] RANK: $y[0]";
}
echo "<p>";
$x++;
}
?>
Image Image
slushpuppy
User
User
Posts: 873
Joined: Sun Jul 16, 2006 2:23 pm

Postby slushpuppy » Mon Oct 06, 2008 4:03 am

Code: Select all

echo "$skills[$x] LEVEL: " . $y[1] . " EXP: " . $y[2] . " RANK: " . $y[0] ."";


Code: Select all

echo $skills[$x]." LEVEL: " . $y[1] . " EXP: " . $y[2] . " RANK: " . $y[0];


And the proof while() is faster than for()
slush@slush-laptop:~$ time php -r 'for($i = 1; $i <= 1000000; ++$i) {}'

real 0m0.661s
user 0m0.096s
sys 0m0.024s
slush@slush-laptop:~$ time php -r '$i = 1; while($i <= 1000000) {++$i;}'

real 0m0.126s
user 0m0.124s
sys 0m0.008s

^ I thought I might save someone some time :lol:
-
User avatar
JoshR
User
User
Posts: 716
Joined: Tue Jan 01, 2008 7:32 pm
Location: #mSL
Contact:

Postby JoshR » Mon Oct 06, 2008 1:52 pm

Hobold wrote:Thanks everybody, already fixed it.

Code: Select all

<?php
$skills = 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:", "Summoning:", "Dueling:", "Bounty Hunter:", "Bounty Hunter Rogue:", "Fist Of Guthix:");
$site = file("http://hiscore.runescape.com/index_lite.ws?player=".$_GET['nick']);
$x = 0;
while ($x<=28) {
$y = explode(",", $site[$x]);
if ($y[3] != false) {
echo "$skills[$x] LEVEL: $y[1] EXP: $y[2] RANK: $y[0]";
}
else {
echo "$skills[$x] LEVEL: $y[1] EXP: $y[2] RANK: $y[0]";
}
echo "<p>";
$x++;
}
?>



Why are your IF and ELSE statements echoing the same terms?
Srankie
User
User
Posts: 963
Joined: Thu Mar 01, 2007 7:16 pm
Location: #godscript #msl HOLLAND

Postby Srankie » Mon Oct 06, 2008 3:24 pm

My scripts works, arrays will work in quotes ("") but you have to put {} around them.
Image
Image
User avatar
Hobold
User
User
Posts: 60
Joined: Sun Feb 10, 2008 3:33 am
Location: Tubarão, Brazil
Contact:

Postby Hobold » Mon Oct 06, 2008 3:33 pm

Joshh wrote:
Hobold wrote:Thanks everybody, already fixed it.

Code: Select all

<?php
$skills = 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:", "Summoning:", "Dueling:", "Bounty Hunter:", "Bounty Hunter Rogue:", "Fist Of Guthix:");
$site = file("http://hiscore.runescape.com/index_lite.ws?player=".$_GET['nick']);
$x = 0;
while ($x<=28) {
$y = explode(",", $site[$x]);
if ($y[3] != false) {
echo "$skills[$x] LEVEL: $y[1] EXP: $y[2] RANK: $y[0]";
}
else {
echo "$skills[$x] LEVEL: $y[1] EXP: $y[2] RANK: $y[0]";
}
echo "<p>";
$x++;
}
?>



Why are your IF and ELSE statements echoing the same terms?

Lol it should be:

Code: Select all

if ($y[3] != false) {
echo "$skills[$x] POINTS: $y[0] RANK: $y[1]";
}
else {
echo "$skills[$x] LEVEL: $y[1] EXP: $y[2] RANK: $y[0]";
}


Sorry :D
Image Image
Katlyn
User
User
Posts: 939
Joined: Mon Aug 28, 2006 9:12 pm
Location: London

Postby Katlyn » Mon Oct 06, 2008 4:16 pm

[-Srankie-] wrote:My scripts works, arrays will work in quotes ("") but you have to put {} around them.


But that's just ugly.
Srankie
User
User
Posts: 963
Joined: Thu Mar 01, 2007 7:16 pm
Location: #godscript #msl HOLLAND

Postby Srankie » Tue Oct 07, 2008 1:03 pm

"a" . $a[1] . "b" . $a[2] . "c" . $a[3]

isn't ugly?
Image
Image
Katlyn
User
User
Posts: 939
Joined: Mon Aug 28, 2006 9:12 pm
Location: London

Postby Katlyn » Tue Oct 07, 2008 2:55 pm

[-Srankie-] wrote:"a" . $a[1] . "b" . $a[2] . "c" . $a[3]

isn't ugly?


No.

Return to “PHP”

Who is online

Users browsing this forum: No registered users and 1 guest