Results 1 to 9 of 9

Thread: [RESOLVED] php highscore

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    69

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

  2. #2
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    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.
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    69

    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
    Attached Images Attached Images  
    Last edited by troubleshoot; Jul 13th, 2007 at 03:10 PM.

  4. #4
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: php highscore

    Try putting it on a PHP Enabled Server?
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    69

    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.
    Last edited by troubleshoot; Jul 13th, 2007 at 06:52 PM. Reason: testing it on a host now, still having trouble tho

  6. #6
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    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.
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    69

    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.

  8. #8
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    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.
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width