PHP___________简单读取___________谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/18 03:29:39
$fileopen = fopen("test.html","w+");
fseek($fileopen,"0");
$filereadone = fread($fileopen,20);
fwrite($fileopen,$connet);
$filereadtwo = fread($fileopen,20);
echo $filereadone."<br>";
echo $filereadtwo;
fclose($fileopen);

文件被改写了,但前后的内容我却没读出来,有什么错误?

请看w+打开方式的含义:
'w+' 读写方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。

所以你的第一次读出结果肯定为空,因为打开的时候就删除了所有内容。

第二次读出为什么也为空呢,因为写入之后,指针在最后,没有移动到前面来,所以读出内容为空。