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

读定txt文件的有关问题

WBOY
Release: 2016-06-13 12:07:42
Original
924 people have browsed it

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

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

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


二:

<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 />
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template