<?php
Open, Append Way
$fp = fopen ("Demo.txt", "a");
Rewind ($FP);
Echo Ftell ($fp). " <br> ";
Append by default at end of file
Fwrite ($fp, "Hello world\n");
Shut down
Fclose ($FP);
Open it
$fp = fopen ("Demo.txt", "R");
Echo Ftell ($fp). " <br> ";
Fseek ($FP, 4);//Move the pointer back 4 positions
Echo Ftell ($fp). " <br> ";//returns the current pointer position
Echo fread ($FP, 11). " <br> ";
Echo Ftell ($fp). " <br> ";
Fseek ($fp, -3, seek_end);//move 3 bytes from the last, and newline is also a byte
Echo Fread ($FP, 3);
Rewind ($FP);//directly point the file pointer to the beginning
Echo Ftell ($fp). " <br> ";
Shut down
Fclose ($FP);
Open it
$fp = fopen ("Demo.txt", "R");
while (!feof ($fp)) {
Read the file, read n characters at a time
Echo fread ($FP, 1024);
}
Shut down
Fclose ($FP);
Open it
$fp = fopen ("Demo.txt", "R");
If the file is faulted or the end of the file returns True
while (!feof ($fp)) {
Read a file, read one character at a time
echo fgetc ($FP);
}
Shut down
Fclose ($FP);
Open it
$fp = fopen ("Demo.txt", "R");
while (!feof ($fp)) {
Read a file, read one line at a time
Echo fgets ($fp). " <br> ";
}
Shut down
Fclose ($FP);
Content operation of the file