LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-26-2009, 11:32 PM   #1
jumperbee
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Rep: Reputation: 0
Question Parsing a text file to display certain data on my website in php?


Hi! ^^

Im trying to figure out how to display parts of a .db file created by the scorch2000 server to display a player name, games played, score and maybe more...

here is the text file format example:

playername1 password email #ofgames score setting1 setting2 setting3
playername2 password email #ofgames score setting1 setting2 setting3
playername3 password email #ofgames score setting1 setting2 setting3
playername4 password email #ofgames score setting1 setting2 setting3
playername5 password email #ofgames score setting1 setting2 setting3

I dont want to display everything, of course ^^, but how do i get the player name, the number of games he played and his score to display it in a webpage in this fasion:

Name Games Played Score

joe blow1 25 9876890
joe blow2 31 8989767
joe blow2 26 7989767
joe blow2 17 5989767
joe blow2 13 4989767

and by highest score because the log doesin't put them in in score order....

please help, i asked the maker because he has one runing already but no answer back, well the game is pretty old so i didn't really expect an answer anyways and tryed to figure it out but i dont know functions in php, this is to include in a php-nuke block (this i know how to do

here is an example of a working page at the developper website:
http://scorch2000.com/top100.html

thank you

Last edited by jumperbee; 12-26-2009 at 11:58 PM.
 
Old 12-27-2009, 04:11 PM   #2
ammorais
Member
 
Registered: Nov 2009
Location: Lisbon, Portugal
Distribution: Gentoo, CentOs, Ubuntu, Debian
Posts: 182

Rep: Reputation: 49
I'll send you the bill later.

PHP Code:
<table border="1" borderColor="black" cellSpacing="0" cellPadding="5">
<tr bgcolor="#aaaaaa"><TH>playername1</TH><TH>password</TH><TH>email</TH><TH>#ofgames</TH><TH>score</TH><TH>setting1</TH><TH>setting2</TH><th>setting3</th></TR>

<?php
    $handle 
fopen("file.db""r");
    
    if (
$handle) {
    
        while (!
feof($handle)) {
            
$buffer fgets($handle4096);
            
$line_arr explode(' '$buffer);
            
            echo 
"<tr>";
            foreach(
$line_arr as $value)
            {
                echo 
"<td>$value</td>";
            }
            echo 
"</tr>";            
        }
    }
?>
</table>
 
Old 12-27-2009, 05:03 PM   #3
jumperbee
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 0
Thumbs up ^^ thanks!

Seriously if you have a paypal account it would be my pleasure to give you a little something , im not rich but i'll give you what i can....

you can send your info here admin@excelclan.com if you wish,, like i said it would be a pleasure because this is actually the first code i know that is tailor made for this classic game server so i thank you VERY much and is very much appreciated ^^

Thanks again
 
Old 12-27-2009, 05:06 PM   #4
jumperbee
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 0
Woooooooooooooooow this looks nice! hihihihi ^^
 
Old 12-27-2009, 05:21 PM   #5
jumperbee
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ammorais View Post
I'll send you the bill later.

PHP Code:
<table border="1" borderColor="black" cellSpacing="0" cellPadding="5">
<tr bgcolor="#aaaaaa"><TH>playername1</TH><TH>password</TH><TH>email</TH><TH>#ofgames</TH><TH>score</TH><TH>setting1</TH><TH>setting2</TH><th>setting3</th></TR>

<?php
    $handle 
fopen("file.db""r");
    
    if (
$handle) {
    
        while (!
feof($handle)) {
            
$buffer fgets($handle4096);
            
$line_arr explode(' '$buffer);
            
            echo 
"<tr>";
            foreach(
$line_arr as $value)
            {
                echo 
"<td>$value</td>";
            }
            echo 
"</tr>";            
        }
    }
?>
</table>


This works great but puts all of the line in playername1,, how do i display only the player name in that field, then in the next the numbers of games he player then after that the score in the next field? or how does the script work?

sorry about that here is what it looks like http://www.excelclan.info/games/scor...layerstats.php

Also i cant copy paste the players.db file because it only copies the first word of the file in notepad++ because of the NUL symbols (dont know why) so i have attached a picture of the file....
Attached Thumbnails
Click image for larger version

Name:	playersdb.jpg
Views:	13
Size:	65.6 KB
ID:	2346  

Last edited by jumperbee; 12-27-2009 at 05:50 PM. Reason: picture
 
Old 12-27-2009, 06:10 PM   #6
jumperbee
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 0
ok i figured out that $line_arr = explode(' ', $buffer); this is the value that takes in to account that after the space it becomes the next value, but in this log file there is a NUL symbol, what is this?, what can i put between the quotes in $line_arr = explode('HERE', $buffer); to represent that NUL symbol?
 
Old 12-27-2009, 06:39 PM   #7
jumperbee
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 0
ok

ok the problem is that the server removes those NUL symbols and i loose the spaces,, is there a way to read that file with this script while keeping the spaces?

or can i copy this file to the location of this script, covert it to another format and read it,, but how or with what do i convert it?, i know how to copy it with cron and all but what program on an ubuntu server can i use to convert this file to unicode or a format wich keeps the spaces?

thanks

Last edited by jumperbee; 12-27-2009 at 06:41 PM.
 
Old 12-27-2009, 06:57 PM   #8
ammorais
Member
 
Registered: Nov 2009
Location: Lisbon, Portugal
Distribution: Gentoo, CentOs, Ubuntu, Debian
Posts: 182

Rep: Reputation: 49
What is the format of the db file?
I use the function explode(' ', $buffer) that separates the words by space.
For example. The line
Code:
something1 this is a phrase something2
will be converted to an array of 5 words
Code:
something1
this
is
a
phrase
something2
If you want the spaces the db file must have a diferent format. For example like this:
Code:
something1,this is a phrase,something2
Then change the
PHP Code:
explode(' '$buffer
to
PHP Code:
explode(','$buffer
The result will be an array with 3 words
Code:
something1
this is a phrase
something2
For more info have a look at explode documentation

It's also possible that the db file separates phrases with tabs. If that's the case simple change the explode line to

PHP Code:
explode("\t"$buffer); 
[EDIT]

You mentioned the NUL symbol:
Try:
PHP Code:
explode("\0"$buffer
[/EDIT]

Last edited by ammorais; 12-27-2009 at 07:04 PM. Reason: additional info
 
Old 12-27-2009, 07:16 PM   #9
jumperbee
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 0
Notepad++ tells me that this is an ANSI Windows format, it is generated by the game server wich uses java.

I tryed the "\0" found that out on wikipedia but still shows the same thing... all together... also tryed with your suggested "\t" (tabs), no go
Attached Files
File Type: txt players.txt (493 Bytes, 12 views)

Last edited by jumperbee; 12-27-2009 at 07:22 PM.
 
Old 12-27-2009, 07:21 PM   #10
ammorais
Member
 
Registered: Nov 2009
Location: Lisbon, Portugal
Distribution: Gentoo, CentOs, Ubuntu, Debian
Posts: 182

Rep: Reputation: 49
can you zip it and atatch it?
 
Old 12-27-2009, 07:24 PM   #11
jumperbee
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 0
I attached it to my last post,, i changed the extension to txt from db,, but if you open it with notepad++ you see the NUL symbols....

thank you very much ^^
 
Old 12-27-2009, 07:37 PM   #12
jumperbee
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 0
here it is in a zip format with the extention .db, arff cant attach zip files.... but i posted it in txt format above...

Last edited by jumperbee; 12-27-2009 at 07:38 PM.
 
Old 12-27-2009, 07:42 PM   #13
ammorais
Member
 
Registered: Nov 2009
Location: Lisbon, Portugal
Distribution: Gentoo, CentOs, Ubuntu, Debian
Posts: 182

Rep: Reputation: 49
Ok. Let me check
 
Old 12-27-2009, 07:50 PM   #14
ammorais
Member
 
Registered: Nov 2009
Location: Lisbon, Portugal
Distribution: Gentoo, CentOs, Ubuntu, Debian
Posts: 182

Rep: Reputation: 49
Ok. The end of line is 0x0A and the words are separated by 0x00

I also sorted the results by Score

PHP Code:
<TABLE border="1" borderColor="black" cellSpacing="0" cellPadding="5">
<TR bgcolor="#aaaaaa"><TH>playername1</TH><TH>password</TH><TH>email</TH><TH>#ofgames</TH><TH>score</TH><TH>setting1</TH><TH>setting2</TH><th>setting3</th></TR>

<?php
    $filename 
"players.txt";
    
$handle fopen($filename"r");
    
$multi_arr = array();
    if (
$handle) {
    
        
$buffer fread($handlefilesize($filename));
        
$lines explode(chr(10), $buffer);
        foreach(
$lines as $line)
        {

            
$multi_arr[] = explode(chr(0), $line);        
        }        
    }
    
$sort_ = array();
    foreach(
$multi_arr as  $value) {
            
$sort_[] = $value[4];
    }
        
    
array_multisort($sort_SORT_DESCSORT_NUMERIC$multi_arr);
    foreach(
$multi_arr as $value1)
    {
        echo 
"<tr>";
        foreach(
$value1 as $value2)
        {
            echo 
"<td>$value2</td>";
        }
        echo 
"</tr>";
    }
?>
</table>
 
Old 12-27-2009, 07:52 PM   #15
jumperbee
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 0
kewwwwlll!,, ok i checked the link you provided on the explode() argument but i cant see anything that explains on how to print only chunks of a line, for example mine has 14 values,, but how do i only print the name, the numbers of games played and the score?, because the other values are passwords and e-mails i wouldn't want to display that to the public.....

if you dont feel like explaining can you provide me with the argument i can use to do this?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
need a php script to format and display a select amount of text from a file steve51184 Linux - Software 27 01-27-2009 02:29 PM
Parsing text file sandeepsudeep Linux - Newbie 7 10-09-2007 05:34 AM
parsing text file in php ohcarol Programming 1 08-25-2006 09:18 AM
inserting the data thru php in a text file suchi_s Programming 5 02-02-2005 03:28 AM
need help parsing text file airman99 Linux - General 2 10-08-2004 09:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration