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);
Last edited by troubleshoot; Jul 12th, 2007 at 04:02 PM.
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.
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.
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.