Home >Backend Development >PHP Tutorial >读定txt文件的有关问题

读定txt文件的有关问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:07:42957browse

读定txt文件的问题
一。请问怎么每次把内容写入txt文件的第一行。

二。请问怎么读取txt文件的最后一行。
------解决思路----------------------
一:

<br />$handle  =  fopen ( 'a.txt' ,  'r+' );<br />rewind($handle);<br />fwrite($handle,"这是第一行\r\n");<br />fclose ( $handle );<br />


二:

<br /><br />$handle  =  fopen ( 'a.txt' ,  'r+' );<br />$arr=array();<br />while($line=fgets($handle)){<br />    $arr[]=$line;<br />}<br />fclose ( $handle );<br />echo end($arr);<br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn