Posted by Fang on 11/01/05 03:24
I want to open a file and write some string between the the 3rd line and the
4th line. my code (as follows) can insert after the 3rd line but somehow it
owerwrites the 4th line. So i lost its original content. As my original file has
more than 10000 lines of code, I'm looking for a handy way to do that. Does
anyone know how I can fix it? Please help me. Thanks very much.
$content = "new content here\n"
$handle = fopen("test.wrl", "r+"); //open file
$theData = "";
$i = 1;
while($i<4){
$theData += fgets($handle);
$i++;
}
fputs($handle, $content); //write
fclose($handle); //close it
Navigation:
[Reply to this message]
|