Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-10-2005, 05:59 PM Text files
log2's Avatar
Skilled Talker

Posts: 80
Trades: 0
Ok, I have a small script that writes something to a text file... I'd like to know how to delete the text that are after number 10... and when someone writes a new text it deletes the last one... Or and I'd also like to know how to only show the first 20 entries from a text file.. They aren't sepereated onto lines or anything... (by the way... it's not the same text file and it's not the same script )
EDIT: oh crap... (pardon my language) I am in the wrong forum... but seeing as how I've already posted it, could someone help me anyway

Last edited by log2; 03-10-2005 at 06:03 PM..
log2 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-10-2005, 07:46 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
What scripting language is it written in? If we move your post to the right place it is more likely to get a useful response.
__________________
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)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-11-2005, 10:57 AM
log2's Avatar
Skilled Talker

Posts: 80
Trades: 0
well it's PHP, at least it should be
__________________

Please login or register to view this content. Registration is FREE
The future is now with 4D Realms
log2 is offline
Reply With Quote
View Public Profile
 
Old 03-11-2005, 12:14 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Moved.
__________________
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)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-11-2005, 12:32 PM
log2's Avatar
Skilled Talker

Posts: 80
Trades: 0
thanks
__________________

Please login or register to view this content. Registration is FREE
The future is now with 4D Realms
log2 is offline
Reply With Quote
View Public Profile
 
Old 03-11-2005, 04:49 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Could you give us an example of how the text file is put together? You said that things weren't divided onto lines. We'll need to know how the file is structured to know which parts to pick out and move around etc.
__________________
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)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-11-2005, 05:55 PM
log2's Avatar
Skilled Talker

Posts: 80
Trades: 0
well it's just text... no spaces between the new entries or anything... it's just text all together until it's pushed to a new line
__________________

Please login or register to view this content. Registration is FREE
The future is now with 4D Realms
log2 is offline
Reply With Quote
View Public Profile
 
Old 03-11-2005, 06:37 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
How would you as a human being tell where one ended and the next began? There must be some defining feature that will allow you to split them up.

If you are going to be adding new entries to this file I would recommend you put each one on a new line, or use commas or similar to break it up since this make s the job of reading it out with a script a lot easier.
__________________
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)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-11-2005, 07:16 PM
log2's Avatar
Skilled Talker

Posts: 80
Trades: 0
but it can be long, if the person leaves a message it could take up the entire line and then some, so that's why I didn't do it that way, and the way I tell it ends being a human, I read it and look for the </table><br><table> tags, they're in that order
__________________

Please login or register to view this content. Registration is FREE
The future is now with 4D Realms
log2 is offline
Reply With Quote
View Public Profile
 
Old 03-13-2005, 04:08 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
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)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Reply     « Reply to Text files
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.86772 seconds with 12 queries