One. How do I write the content to the first line of the TXT file each time.
Two. How do I read the last line of the TXT file?
Reply to discussion (solution)
One:
$handle = fopen (' a.txt ', ' r+ '); Rewind ($handle); Fwrite ($handle, "This is the first line \ r \ n"); fclose ($handle);
Two:
$handle = fopen (' a.txt ', ' r+ '); $arr =array (); while ($line =fgets ($handle)) { $arr []= $line;} Fclose ($handle); Echo End ($arr);
One. That write txt first line to the original content of the TXT file is cleared, I want to keep the original content, new content inserted into the first line.
$str = "This is the first line \ r \ n"; $handle = fopen (' a.txt ', ' r+ '); while ($line =fgets ($handle)) { $str. = $line; } Fclose ($handle); File_put_contents (' A.txt ', $str);
It seems that there is no direct function to achieve, can only loop out the data, thank you