PHP fread()函数用于读取文件的数据。 它需要两个参数:文件资源($handle)和文件大小($length)。
语法
string fread (resource $handle , int $length )
$handle表示由fopen()函数创建的文件指针。
$length表示要读取的字节长度。
示例
$contents";//printing data of file
fclose($fp);//close file
?>
上面代码执行结果如下 -
this is first line this is another line this is third line
PHP读取文件 - fgets()函数
PHP fgets()函数用于从文件中读取单行数据内容。
语法
string fgets ( resource $handle [, int $length ] )
示例
上面代码输出结果如下 -
this is first line
PHP读取文件 - fgetc()函数
PHP fgetc()函数用于从文件中读取单个字符。 要使用fgetc()函数获取所有数据,请在while循环中使用!feof()函数作为条件。
语法
string fgetc ( resource $handle )
示例
上面代码输出结果如下 -
this is first line this is another line this is third line



