PHP中的fflush()函数是一个内置函数, 用于将所有缓冲的输出写入打开的文件。 fflush()函数强制将所有缓冲的输出写入文件句柄指向的资源。 fflush()函数返回true成功与false失败。
语法如下:
fflush($file)
参数:PHP中的fflush()函数仅接受一个参数$ file。它指定打开的文件流。
返回值:成功返回TRUE, 失败返回FALSE。
错误与异常:
- 如果文件指针无效, 则fflush()函数将导致错误。
- 指向的文件必须由fopen()或fsockopen()打开, 并由fclose()关闭。
程序1:在以下程序中, 文件名为singleline.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.
参考:
【PHP fflush()函数用法介绍】http://php.net/manual/en/function.fflush.php
推荐阅读
- 算法设计(可以删除的最长子字符串的长度)
- Android生成二维码
- 腾讯Bugly干货分享Android Linker 与 SO 加壳技术
- 解决Android5.0以后DataPicker选择时间无效的bug。
- Android 关于录音文件的编解码 实现米聊 微信一类的录音上传的功能
- Android 三种方式实现自定义圆形进度条ProgressBar
- android studio 控制台中文乱码
- Android开发(最全面最易懂的Android屏幕适配解决方案)
- 关于AndroidSQLite数据库后台处理的小例子