Solar Posted November 6, 2008 Share Posted November 6, 2008 Hello, I am new to the forums and I am looking for some help. Hehe, This is the right place I hope. I am running a server on a game and wanting server stats. This game automatically generates itself to a certain folder, I've placed it on my hosting files, which I am using apache. So there automatically generated into the same folder. Which still can be viewed because I have it set up. But with this text file, The beginning of a new line, doesn't always seem to work. Let me point you to a example; http://sweb.redirectme.net/ss/ladder.php As you can see that the points, and the user are bunched up together without starting a new line. My question is; Is there a way of putting a command line into the .php file that will make the Score and the Username beside eachother and a way to make it "Begin A New Line" instead of having to edit the .txt Because it automatically generates itself and will erase whats being put? Thanks PHPFREAKS, Solar P.S. I am new at php, go easy on me Quote Link to comment Share on other sites More sharing options...
peranha Posted November 6, 2008 Share Posted November 6, 2008 puting an HTML line break will force to the next line <br /> Quote Link to comment Share on other sites More sharing options...
Solar Posted November 6, 2008 Author Share Posted November 6, 2008 Sorry I should have been more specific.. I'm using a line like this in my ladder.php file. <?php include("/../../../Documents and Settings/Steven/Application Data/Armagetron/var/ladder.txt"); ?> Anyway of editing something in between or after that will allow it to have a next line instead of updating the .txt file which will get overwrited because of server status updates? Quote Link to comment Share on other sites More sharing options...
xnowandtheworldx Posted November 6, 2008 Share Posted November 6, 2008 Where exactly do you want the lines to end at? Can you possibly give us an example of what the .txt file looks like? Quote Link to comment Share on other sites More sharing options...
xnowandtheworldx Posted November 6, 2008 Share Posted November 6, 2008 Here, I whipped this up in about 5 minutes it's probably not the best way to do it, but it will get the job done. I'll see what else I might be able to do with it. But note that this will only work as long as spaces aren't allowed in the names for the game. If spaces are allowed that users username will mess it all up, which is why this really isn't the best way to do it. If I come up with anything else i'll let you know. <?php $file = "foo.txt"; //specify the file to open $fh = fopen($file, 'r+'); //open up the file with read-only privileges $contents = fread($fh, filesize($file)); //we obtain the contents of the file for parsing $txtChunks = explode(' ', $contents); //we then turn the contents into a massive array using the spaces to seperate the words into "chunks" foreach($txtChunks as $text){ //we loop through our newly created array static $loop = 0; //set the loop counter to 0 and make it static so we know when to echo a break if($loop % 2 === 0 && $loop != 0) { //if the loop can be divided by 2 i.e. we have reached the end of the second word(the username) echo "<br/>"; //echo a break in the page } echo $text . " "; //echo out the text from the array $loop++; //increment our loop } ?> Quote Link to comment Share on other sites More sharing options...
Solar Posted November 6, 2008 Author Share Posted November 6, 2008 Hehe, Almost! I really appreciate this. Seems like its backwards. As you can see, the first number has no person beside, Because the person below has the score of the person below that! I'm going to fiddle untill you respond with it and see if I can fix it. To see for yourself; http://sweb.redirectme.net/ss/ladder.php EDIT: Reading an above post; Example; Score Username Score Username Score Username ... etc. Quote Link to comment Share on other sites More sharing options...
Solar Posted November 6, 2008 Author Share Posted November 6, 2008 Sorry for double posting, wouldn't let me re-edit; The Text File is like this; Score Username Score Username Score Username ...etc As you can see there a two spaces and the score comes first before the username. Fiddling with the script, I still can't figure it out. Quote Link to comment Share on other sites More sharing options...
xnowandtheworldx Posted November 7, 2008 Share Posted November 7, 2008 Ah sorry, well i took a look and it seems like you got it fixed. It seems like the error is that there was a space in the beginning of the actual text file. So basically all you should need to do is change $txtChunks = explode(' ', $contents); to $txtChunks = explode(' ', trim($contents)); that will remove extra whitespace from the beginning and the end. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.