Jump to content

Inserting File


Solar

Recommended Posts

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 ;)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
}
?>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.