txt file (lil help?)
Moderator: General Moderators
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
txt file (lil help?)
ok i am editing a text file line by line, i have it so i can view each line in its own text field with a submit button for each line and all that happy stuff BUT! i don't know how to open a txt file, automatically go to a specific line, then only write to that one line without changing anything else. 
that is more or less impossible. you will have to read the whole file, and then remove/edit that those parts and write the new contents of the file again...
in the case the new string has exactly the same length, you could also position your filepointer with fseek and then fwrite from there...
but as you say you are offering all the lines in separate inputboxes to the user, you could also split your big text file in separate textfiles... this way, you only have to edit the file that is associated to that textbox.
fe: file1.txt with 10 lines would become file1-1.txt, file1-2.txt, ... , file1-10.txt
in the case the new string has exactly the same length, you could also position your filepointer with fseek and then fwrite from there...
but as you say you are offering all the lines in separate inputboxes to the user, you could also split your big text file in separate textfiles... this way, you only have to edit the file that is associated to that textbox.
fe: file1.txt with 10 lines would become file1-1.txt, file1-2.txt, ... , file1-10.txt
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
alright well nothing is impossible (well i hope THIS isnt impossible because i will be SOL if it is) but is there a way to calculate the amount of bytes up to a certain line so i can set the file pointer to the line i want with fseek? or do i not know what im talking about at all?
that way seams a little...sloppy...any other sugestions?timvw wrote:fe: file1.txt with 10 lines would become file1-1.txt, file1-2.txt, ... , file1-10.txt
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
ok well yes a database mite be easier or somtin maybe but i am using flat txt files because:
1) i need to learn them sooner or later
2) my father died in a horrible train crash involving nothing but sql
what im doing is making a news script and for every news topic thing added a txt file is made to for the comments section so all comments that are posted are saved to that news topics specific txt file. so in the admin page i want to be able to edit comments made by other users. i have this for the showing of the individual lines for editing
but how do i make it so when i hit the individual submit button it replaces the line with the number of linenum...u know what i mean(i hope)
1) i need to learn them sooner or later
2) my father died in a horrible train crash involving nothing but sql
what im doing is making a news script and for every news topic thing added a txt file is made to for the comments section so all comments that are posted are saved to that news topics specific txt file. so in the admin page i want to be able to edit comments made by other users. i have this for the showing of the individual lines for editing
Code: Select all
<?php
$txt = "comments/$file";
$opentxt = fopen($txt, 'r');
?><form action="admin.php?id=editcomments2&file=<? print $file; ?>" method="post"><?
$i = 1;
while (!feof($opentxt)) {
$readtxt = fgetss($opentxt, 5000);
?><input type="text" name="editedcom" value="<? print $readtxt; ?>">
<input type="submit" name="submit" value="Edit Text">
<input type="hidden" name="linenum" value="<? print $i; $i++; ?>">
</form>
<br>
<?
}
fclose($opentxt);
?>- carlmcdade
- Forum Newbie
- Posts: 24
- Joined: Thu Dec 02, 2004 2:19 am
- Location: sweden
I always point to this tutorial becasue the comments are so that they make it hard not to understand 
http://codewalkers.com/tutorials/57/9.html
http://codewalkers.com/tutorials/57/9.html