Someone789 Posted June 10, 2008 Share Posted June 10, 2008 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! Quote Link to comment Share on other sites More sharing options...
phpzone Posted June 10, 2008 Share Posted June 10, 2008 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; } } ?> Quote Link to comment Share on other sites More sharing options...
Someone789 Posted June 11, 2008 Author Share Posted June 11, 2008 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. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 11, 2008 Share Posted June 11, 2008 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. Quote Link to comment Share on other sites More sharing options...
Someone789 Posted June 11, 2008 Author Share Posted June 11, 2008 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. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 11, 2008 Share Posted June 11, 2008 My bad, try: $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 (Works, I just tried it on my PHP server) Quote Link to comment Share on other sites More sharing options...
Someone789 Posted June 11, 2008 Author Share Posted June 11, 2008 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? Quote Link to comment Share on other sites More sharing options...
trq Posted June 11, 2008 Share Posted June 11, 2008 Put this at the very top. <?php ini_set('display_errors','1'); error_reporting(E_ALL); ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 11, 2008 Share Posted June 11, 2008 http://96.224.250.205:6969/testpost.php Check it out for yourself. Click the View Source button to see what I did... (Copied and pasted what you had in the code box, btw) Quote Link to comment Share on other sites More sharing options...
Someone789 Posted June 11, 2008 Author Share Posted June 11, 2008 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) Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 11, 2008 Share Posted June 11, 2008 Don't take this wrong way, but how about moving on from crappy free hosts and just paying for a domain and hosting? =/ Quote Link to comment Share on other sites More sharing options...
Someone789 Posted June 11, 2008 Author Share Posted June 11, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.