deleting lines from log file<

windows

Guest
Hey everyone,

Just to let you know, im really new to programming so please keep it simple.

What im trying to do is make a php chat applet. I got the thing working but one of the problems is that the file that the posts are being made to keeps growing and growing. I need some way of opening the file up, turning the lines into an array and if the file has more than a certain amount of lines, to delete a specified amount of lines from the top of it.

Right now for one of the things im doing, im using this script to delete 3 lines from the bottom of the file. Is there some way i can change this to check how many lines there are in the file and if there are more than 50 make it delete the first 10 lines off the top?

Thanks for the help in advance.

$myFile = file ('text.php');
$myFile = array_slice($myFile, 0, sizeOf($myFile) - 3);

$fp = fopen('text.php', 'w');
foreach ($myFile as $line) {
fputs($fp, $line);
}

fclose($fp);I think the bigger question is, why are you doing it in a flat file?

if you have a lot of people the sevrver will not keep up with the writes. people will get fopen errors and other stuff.

use a database like mysql.id like to use mysql but the server doesnt have itthat sucks. are you using flock() to protect it being written to while you delete or somebody else is using it?

what does the file look like? can you show about 2-3 lines?No i havent used flock. I dont know much about php, i just mess around with it because i want to learn. I know php chat applets really suck but i just need a crappy chat applet untill i can get on a server with mysql. Within the next month im actualy gonna get a faster internet connection and turn my home computer into a server. better than two three lines i've ziped up what i have so far and attached it to this post.

I think im going to read a bit into flock, but thanks for the help so far. Any other advice or help would be greatly apreciated.

By the way, sorry the html code is garbage becuase i use frontpage to make my webpages.no I need text.php with some lines in it. I don't want the whole chat script.Oh sorry,

here u go, text.php simply looks like this:

<html>
<head>
<title>text</title>
<meta http-equiv="refresh" content="3">
</head>
<body bgcolor="#C0C0C0" onLoad="window.location.hash='anchor'">
<br>
_______________________
<br>
<br> Name: test <br>
Message: test <br>
_______________________
<br>
<br> Name: R榘抏n <br>
Message: What.
<br>
_______________________
<br>
<br> Name: ELOF <br>
Message: What? <br>
_______________________
<a name='anchor'>
<body>
</html>

--------------------oh man. why are you doing it that way? by intering the html into that as well makes it harder to do what you want. I would just store the username and message and have it seperated by a pipe |

a lot less work on your part and easier to delete lines. so it may look like this

<br><br> Name: test <br> Message: test <br>|
<br><br> Name: test <br> Message: test <br>|
<br><br> Name: test <br> Message: test <br>|
<br><br> Name: test <br> Message: test <br>|


easier to write that way and easier to manage.lol, i dunno man, i know nothing. After i get it working properly i want to be able to add the ability to format the text when you post it. Can i still format the text without using html?well depending on how you store things you can do anyhtign you want. are you talking about per user? that might be difficult but also depends on how you store the user settings.
 
Back
Top