|
Posted by programming on 04/11/07 12:15
On Apr 11, 7:08 pm, Toby A Inkster <usenet200...@tobyinkster.co.uk>
wrote:
> programming wrote:
> > say i would like to delete the middle line of this txt, in member.txt
> > what php code or logic would help me accomplish this?
>
> For a small file:
>
> 1. Read member.txt into an array (the "file" function is
> your friend);
> 2. Make the changes to the array (the "unset" function is
> your friend);
> 3. Output the array to "member-new.txt";
> 4. Delete "member.txt";
> 5. Rename "member-new.txt" to "member.txt";
>
> If the file is larger (more than say, 500 kB) this might become a bit
> memory-hungry, and it's worth looking at iterating over each line of the
> file individually rather than reading it all into memory at once.
>
> --
> Toby A Inkster BSc (Hons) ARCS
> Contact Me ~http://tobyinkster.co.uk/contact
> Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
>
> * = I'm getting there!
Thanks for you steps, i had a go at doing it..is this what you meant
by any chance?
<?php
$line = file ("./member.txt", "w");
unset($line);
$line = fopen("./member-new.txt");
unlink("./member.txt")
rename("member-new.txt","member.txt");
fclose($line);
?>
I am getting a parse error, and i am not sure if i am doing this
right??
Parse error: syntax error, unexpected T_STRING in /volumes/data1/home/
pioannou/public_html/php/Assignment11/admin/delete_member.php on line
11
[Back to original message]
|