PHP中的fflush()函数是一个内置函数,用于将所有缓冲输出写入打开的文件。函数的作用是:强制将所有缓冲输出写入文件句柄指向的资源。函数的作用是:返回 符合事实的 论成功与发展 错误的 关于失败。
null
语法:
fflush($file)
参数: PHP中的fflush()函数只接受一个参数$file。它指定打开的文件流。
返回值: 成功时返回TRUE,失败时返回FALSE。
错误和例外 :
- 如果文件指针无效,则fflush()函数会导致错误。
- 指向的文件必须由fopen()或fsockopen()打开,并由fclose()关闭。
下面的程序演示了fflush()函数。
方案1 :在下面的程序中,名为 单线。txt 包含一行信息,即“此文件由一行组成”。
<?php // The file is opened using fopen() function $check = fopen ( "singleline.txt" , "r" ); $seq = fgets ( $check ); // Writing buffered output to a file // until the end-of-file is reached while (! feof ( $check )) fflush ( $check ); // The file is closed using fclose() function fclose( $check ); ?> |
输出:
This file consists of a single line.
方案2 :在下面的程序中,名为 gfg。txt 包含以下文本。
这是第一行。 这是第二行。 这是第三行。
<?php // The file is opened using fopen() function $check = fopen ( "gfg.txt" , "r" ); $seq = fgets ( $check ); // Writing buffered output to a file // until the end-of-file is reached while (! feof ( $check )) fflush ( $check ); // The file is closed using fclose() function fclose( $check ); ?> |
输出:
This is the first line. This is the second line. This is the third line.
参考: http://php.net/manual/en/function.fflush.php
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END