gpt4 book ai didi

php fread文件函数

转载 作者:可可西里 更新时间:2023-11-01 00:22:39 25 4
gpt4 key购买 nike

我写了下面的代码来输出一个文件的内容两次。但它只做了一次。这是为什么?

文本文件内容如下:

My name is Sam. Sam I am.
My name is Chris and Chris I am.
The brown fox jumped over the fence.

代码如下:

<?php
$file = "files/info.txt";
$handle = fopen($file, "rb");
echo fread($handle, filesize($file));
echo fread($handle, filesize($file));
?>

输出:

"My name is Sam. Sam I am. My name is Chris and Chris I am. The brown fox jumped over the fence."

最佳答案

调用 fread()“用完”文件,为了再次调用 fread(),您必须使用 rewind($handle) 将读取指针移回文件开头

关于php fread文件函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15016837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com