File reading

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply

Wed Oct 02, 2002 12:54 pm

Easy enough. This is off the top of my head (as usual) so some of the code might be slightly wrong, but you'll get the gist

Code: Select all

$file_contents = @file("log.txt");
$file_contents[] = (sizeof($file_contents)+1).".\tUsername:\t".$username."\tPassword:\t".$password."\n";

You want something like that, let me take you through it:
The 1st line loads all the lines of the file into the array $file_contents (the key is line No, the value is the line).
The 2nd line adds another value to the end of the array, the sizeof gets how many lines there are, then adds one (so the line number is correct), and the \t puts in a tab space.

Once you've got all that done, just write it!

Post Reply