Jump to content

[SOLVED] Pulling Values from an external PHP page


Someone789

Recommended Posts

Hi,

 

I'm hopeful that this will be a relativity simple problem to solve, but as my PHP knowledge doesn't go too far, I need some help with this.

 

There is a page on a gaming website specifically designed to output raw data (without any HTML formatting) that is constantly updated. I'm looking to pull away some of these data values to place on my page, so I don't have to continually update them by hand. Here's an example of an output page:

 

http://hiscore.runescape.com/index_lite.ws?player=zezima

 

As you can see, the source code displays exactly as:

54,2361,1169704083

156,99,57297222

151,99,46201888

280,99,36579898

67,99,56040170

75,99,36143705

204,99,14109288

8,99,61536452

5,99,200000000

928,99,22078423

15,99,104632668

172,99,26010252

9,99,116979576

517,99,13549522

69,99,17523465

237,99,15743643

4,99,51425879

291,99,13514354

5,99,200000000

235,99,15719540

104,99,19295611

209,99,15967127

2409,99,13144963

180,99,13197167

1152,84,3013270

2175,1944

-1,-1

-1,-1

-1,-1

Say I wanted to grab the bolded number out of that data set to display on my website - is there a simple way that this could be done?

 

Thanks! :)

Link to comment
Share on other sites

It depends on what you're after achieving, for instance you say you want the 63526452.

 

What is the qualifying reason for getting this number?

 

Is the bit before it "8,99" a user ID then Rank or something?

 

If that's the case and you're look for something like that then you need to parse the file with a regular expression, or recurse through each

line and check the first entry until you find the one you want.

 

If you PHP configuration allows you can open the file directly with fopen (http://uk3.php.net/fopen) or file (http://uk3.php.net/file), if not, download the file with curl (http://uk3.php.net/curl)

 

You could regularly grab the file and store in a database also?

 

Something like the following would download the file and output it, you need to figure out the storage part...

 


<?php
   $file = file('http://hiscore.runescape.com/index_lite.ws?player=zezima');

   foreach( $file as $line )
   {

        $parts = explode( ",", $line );

        if ( count( $parts ) == 3 )
        {

              list( $user_id, $rank, $score ) = $parts;

              print <<<_SCORECARD

                <p>
                User ID $user_id <br />
                Rank is $rank<br />
                Score is $score
                </p>

_SCORECARD;

        }

   }
?>

 

 

Link to comment
Share on other sites

Thanks for the reply.

 

Sorry, I should have explained in more detail. Each line of numbers represents stats for a specific skill and is ordered in this format: Rank, Level, Experience. (Here's a short explanation page for the raw data: http://www.runescape.com/kbase/viewarticle.ws?article_id=201 )

 

The link I provided is simply a "lite" version of the full hiscores. For example, http://hiscore.runescape.com/index_lite.ws?player=zezima is the "lite" version of http://hiscore.runescape.com/hiscorepersonal.ws?user1=zezima

 

Both the full and lite versions display the exact same data and are updated at the exact same time. However, it's obviously much easier to work with the lite version for my purposes, seeing as it doesn't include any HTML formatting. The reason I only want the "63526452" (not really this specific number - just whatever number is in that exact position, as it will increase in value as the player gains more Experience) is because I'm only interested in pulling the Experience, and not the Rank or Level.

 

Something like the following would download the file and output it, you need to figure out the storage part...
Just a quick note - I don't need to store the value in a database, I only need it to output.

 

Just as an example, I'd essentially have this sentence on my website: "The current Experience points this player has is [insert Pulled number]." I don't need to store the values, all I need is for the page to display the number in that position each time someone would refresh the page. Though of course, since that number increases slightly every so often, I'm hoping to use PHP so I don't have to constantly update it by hand.

 

Thanks for that bit of code as well, though I'm afraid I don't really know where to go from there as to getting that number to display on my page.

 

I searched around on these forums and located a thread with a similar question involving this game's lite highscores: http://www.phpfreaks.com/forums/index.php/topic,156933.0.html - Hopefully that might be of any help? What that person was looking to do was far more complicated and involved making dynamic forum signature images which constantly updated with all of the highscore values, so perhaps there's already something in there which may be of use in simply displaying one text value on my website?

 

Hope that clarified the situation - thanks in advance for any additional help I receive.

Link to comment
Share on other sites

If it's always the 8th line:

 

$raw = file_get_contents("http://hiscore.runescape.com/index_lite.ws?player=zezima");

$seper = explode(" ", $raw);

foreach ($seper as $k=>$v) {

  $seper[$k] = explode(",", $v);

}

echo $seper[7][2];  //8th row, 3rd column

 

Should be good from there. Obviously you can change the row/column by changing the array keys.

Link to comment
Share on other sites

Thanks - this is exactly the sort of code I was looking for. And yes, each number is always in the same exact position, though each number slightly increases as time goes on as the player earns more experience points in the various areas.

 

I now have this code:

<?php
$raw = file_get_contents("http://hiscore.runescape.com/index_lite.ws?player=zezima");
$seper = explode(" ", $raw);
foreach ($seper as $k=>$v) {
   $seper[$k] = explode(",", $v);
}
echo $seper[7][2];  //8th row, 3rd column
?>

Unfortunately, this simply displays a blank page whenever I try it. :(

 

Link to comment
Share on other sites

Hmm, still not getting it. I created a notepad file named "test.php" and placed only the following code inside of it:

<?php
$raw = file_get_contents("http://hiscore.runescape.com/index_lite.ws?player=zezima");
$seper = explode("\n", $raw);
foreach ($seper as $k=>$v) {
   $seper[$k] = explode(",", $v);
}
echo $seper[7][2];  //8th row, 3rd column
?>

Once it was uploaded via FTP to my website, I viewed the test.php page and it was completely blank (I checked the source code and it was completely blank as well). The host I'm using is a free host - however I'm also hosting a fully functional PHPBB3 board on it as well, so I know it has to be fully configured for PHP.

 

Any ideas?

Link to comment
Share on other sites

Ah ok, looks like the problem is definitely just on my end.

 

Using:

<?php ini_set('display_errors','1'); error_reporting(E_ALL); ?>
<?php
$raw = file_get_contents("http://hiscore.runescape.com/index_lite.ws?player=zezima");
$seper = explode("\n", $raw);
foreach ($seper as $k=>$v) {
   $seper[$k] = explode(",", $v);
}
echo $seper[7][2];  //8th row, 3rd column
?>

 

I got:

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home/vol3/byethost10.com/b10_1707440/htdocs/New folder/test.php on line 3

 

Warning: file_get_contents(http://hiscore.runescape.com/index_lite.ws?player=zezima) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home/vol3/byethost10.com/b10_1707440/htdocs/New folder/test.php on line 3

 

Notice: Undefined offset: 7 in /home/vol3/byethost10.com/b10_1707440/htdocs/New folder/test.php on line 8

 

Guess this means I'll have to switch to a new host that allows a certain PHP function? (Strange though, this is the first time I've ever had an error like this with this host, as it's handled lots of complicated PHP scripts in the past very well)

Link to comment
Share on other sites

Heh, guess that's what I'll be doing then. In the past, this free host always covered all of my needs (MySQL, no advertisements at all, completely free, PHP 5, etc) so I never bothered with looking elsewhere - but if you're saying that the reason this script is failing is due to the host itself, then yep, I'll be moving to a better one.

 

Thanks all!

 

Edit: Actually, I'll keep this open for just a bit longer in case anyone knows a way to get around those errors on my current host, but I'll mark it as solved in a few hours if there are no further posts.

Link to comment
Share on other sites

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.