我编写了下面的代码来输出文件的内容两次.但它只做了一次.这是为什么?
文本文件内容如下:
My name is Sam. Sam I am.
My name is Chris and Chris I am.
The brown fox jumped over the fence.
Run Code Online (Sandbox Code Playgroud)
代码如下:
<?php
$file = "files/info.txt";
$handle = fopen($file, "rb");
echo fread($handle, filesize($file));
echo fread($handle, filesize($file));
?>
Run Code Online (Sandbox Code Playgroud)
输出:
"My name is Sam. Sam I am. My name is Chris and Chris I am. The brown fox jumped over the fence."
Run Code Online (Sandbox Code Playgroud)
调用fread()"用完"文件,为了再次fread()它你必须使用rewind($ handle)将读指针移回文件的开头