Posts: 1,832
Location: Somewhere else entirely
|
I honestly don't think you need to worry about the length of a line - yes text editors will wrap lines onto the next one, but as far as php is concerned if there is no line break ( a \n symbol) then it is all one line. I tried this on a line with over a million characters in it and there was no problem at all.
Cptnwinky recently brought the file() function to my attention and this would be particularly well suited to this kind of task.
The file function reads a file and places the lines of the file into an array. To add a new entry and delete the oldest one, you just need to write back into the file only entries 2 up to 10, and then add the new one on the end:
PHP Code:
$lines = file("test.txt");
$fp = fopen("test.txt","w");
for($i = 1; $i < count ($lines); $i++) {
fwrite($fp,$lines[$i]);
}
fwrite($fp,"This is a new entry\n");
Once things are all on one line each, reading the first 20 becomes really easy, you just loop through the first 20 items in the file() array and ignore the rest.
When you say that you file is 'text altogether until it is pushed to a new line' what you probably mean is that your text editor displays it as being on a new line, when in fact your entire file is probably one line anyway. If you still want to do things without line breaks, this is possible but harder and more error prone than doing it with lines.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';
Please login or register to view this content. Registration is FREE (aka MSN handwriting for forums)
|