Help - Search - Members - Calendar
Full Version: scoreboard
BleepingComputer.com > Software > Programming
   
hintswen
hi. there's a bot which saves people's scores in a ini file and i was wondering if there is a way to get php to read the file, display the information in a table and sort it.
hintswen
still no luck on this. awaiting sugestions...
groovicus
It sort of depends on whose system the .ini file is, what encoding may have been used on the data, if you have a means of decoding the data, etc.
Grinler
Where is the .ini file located? Same as where the script will be? What is the format of the ini file?
hintswen
ini files would be in same place as the script and i think the format is like this:

[nickname]
win=10
loss=3
score=40

it would be similar to that maybe with a few more lines.
groovicus
Something like this?
http://www.metalshell.com/view/source/96/

That's as far as I can help, but I found about 1000 unique pages for using PHP. smile.gif It doesn't look too complex.
hintswen
kinda, i need it displayed in table format, nicknames down the left and scores going across. later i'll try edit that script but i'm no good at php.
groovicus
I'm sorry. I just re-read your question..

The answer is.. Yes. smile.gif

EDIT: Umm.. I guess that sounds a little harsh.... let me rephrase things a little. The script I put up there was the first one I found when I Googled. All it does is reads a file. I don't know how it is stored, or how to manipulate it after that. That was probably a little further down on the search list. wink.gif

It is completely possible to do everything that you want to do. There is plenty of sample code available on the web, you will just have to learn to manipulate the language. I don't know anything about php at all, but I bet I could find enough examples and tuts that I could noodle together a passable script before too terribly long. It probably wouldn't be pretty, but I have no doubt I could do it. I happen to like scripting languages though because they are pretty simple.

Is there any reason in particular that you want to do it in php? I am assuming that like jsp that one needs some kind of server software in order to serve up the web pages.. do you have that?
hintswen
you've lost me there but it doesn't really matter anymore.

I was going to host a site for a friends IRC bot. it's a game and the highscores are saved in ini files. i was looking for this script so that he could just upload the ini file and the scores would be displayed. I don't think he runs his bot anymore thow.
Grinler
I found this code off of http://us3.php.net/parse_ini_file. Copyright © 2005 Justin Frim <phpcoder@cyberpimp.pimpdomain.com>


CODE
<?

$ini_array = readINIfile("scoreboard.ini","");


foreach($ini_array as $value=>$key) {

//  Your code here for reading the array ini_array and displaying the variables.


}


function readINIfile ($filename, $commentchar) {
  $array1 = file($filename);
  $section = '';
  foreach ($array1 as $filedata) {
   $dataline = trim($filedata);
   $firstchar = substr($dataline, 0, 1);
   if ($firstchar!=$commentchar && $dataline!='') {
     //It's an entry (not a comment and not a blank line)
     if ($firstchar == '[' && substr($dataline, -1, 1) == ']') {
       //It's a section
       $section = strtolower(substr($dataline, 1, -1));
     }else{
       //It's a key...
       $delimiter = strpos($dataline, '=');
       if ($delimiter > 0) {
         //...with a value
         $key = strtolower(trim(substr($dataline, 0, $delimiter)));
         $value = trim(substr($dataline, $delimiter + 1));
         if (substr($value, 1, 1) == '"' && substr($value, -1, 1) == '"') { $value = substr($value, 1, -1); }
         $array2[$section][$key] = stripcslashes($value);
       }else{
         //...without a value
         $array2[$section][strtolower(trim($dataline))]='';
       }
     }
   }else{
     //It's a comment or blank line.  Ignore.
   }    
  }
  return $array2;
}

?>
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.