-
[RESOLVED] php highscore
Hi, can sombody help me to make a highscore list, reading from a flat file
and display in a table, $PlayerName / $Reputation
textfile looks like this.
mandy|404
jack|40
jim|43
just some random codes i found which may help you, i havent a clue about php but it may help to open the file, and the other to split the data to display in the table
$fp = fopen('highscores.txt','r');
if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;}
list ($PlayerName, $Reputation) = split ('|', $line);
-
Re: php highscore
PHP Code:
$conts = file_get_contents('highscores.txt');
$lines =explode("\n", $conts);
echo '<table width="100%" border="1"><tr><th>Player Name</th><th>Reputation</th></tr>';
foreach($lines As $line) {
list ($playerName, $playerReputation) = split ('|', $line);
echo '<tr><td>'.$playerName.'</td><td>'.$playerReputation.'</td></tr>';
}
echo '</table>';
Hope that helps.
-
1 Attachment(s)
Re: php highscore
thank you for the help, i added phptags and tried running it in phpeditor from my desktop..but it dont seem to list the data
-
Re: php highscore
Try putting it on a PHP Enabled Server?
-
Re: php highscore
i`ll get back to you, the clients ready..it uploads the highscore list to the ftp,
im just waiting on the admin to return home...he owns the website.
-
Re: php highscore
At the top of the script file, put
PHP Code:
error_reporting(E_ALL | E_STRICT);
Then we can see if there's any errors opening the file, or exploding it, etc.
-
Re: php highscore
it gave me a blank white screen, so i googled what you said and used something that proped up
Code:
ini_set("display_startup_errors","1");
ini_set("display_errors","1");
then this happened.
Code:
Warning: split(): REG_EMPTY in C:\Documents and Settings\Main\Desktop\php1F5A.tmp on line 10
Warning: split(): REG_EMPTY in C:\Documents and Settings\Main\Desktop\php1F5A.tmp on line 10
Warning: split(): REG_EMPTY in C:\Documents and Settings\Main\Desktop\php1F5A.tmp on line 10
so i guess line 10 splitfunction is the problem,
changing
list ($playerName, $playerReputation) = split ('|', $line);
to
list ($playerName, $playerReputation) = split ('\|', $line);
fixed the problem!!!!! couldnt be happier thank you,
i dont know why it needed the \ wish i did..but i just tried it because
i saw it in the old splitfunction and thought it was out of place in my first post.
-
Re: php highscore
Ah yeah, my fault.
The split function takes a regular expression as a parameter, and '|' is a special character in regex. Hence you need to escape it (Prepend with '\'), totally my fault for copying that line from your post and being too lazy to write it!!
However, glad you sorted it, click 'Thread Tools' then 'Mark as Resolved' then we all know it's fixed. :)
-
Re: php highscore
Use explode() instead of split() unless you really require a POSIX regular expression as the delimiter, and prefer preg_split() if you need regular expressions.