read a text file and then write back to it only the first 10 lines.
dont work!....help!
$fp = fopen ("$file3", "w+"); $f = file("$file3"); for($i = 0; $i < 10; $i++){ fwrite ($fp, "$f[$i]"); } fclose ($fp);
The "w+" sez: "Open the file for reading and writing." Fine so far, but then, it sez to place the file pointer at the beginning of the file and truncate it to zero length. Bye-bye file!
Use "r+".
Try:
$f = file("$file3"); $fp = fopen ("$file3", "w+"); for($i = 0; $i < 10; $i++){ fwrite ($fp, "$f[$i]"); } fclose ($fp);
cheers! that works.