php使用fread原生读取文件实例demo源码
|
fread读取文件(可安全用于二进制文件) 语法: string fread ( resource $handle,int $length ) fread() 从文件指针 handle 读取最多 length 个字节。 该函数在遇上以下几种情况时停止读取文件: 读取了 length 个字节 到达了文件末尾(EOF) 参数: handle 文件系统指针,是典型地由 fopen() 创建的 resource(资源)。 length 最多读取 length 个字节。 比如现在有一个文件test.txt,其内容如下: manongjc php css java mysql 现在我们使用fread函数读取这个文件里面的内容,源代码如下: $myfile = "./test.txt"; $openfile = fopen ($myfile,"r") or die ("Couldn't open the file"); $file_size=filesize($myfile); /* http://www.manongjc.com/article/1385.html */ $file_content = fread ($openfile,$file_size); fclose ($openfile); echo $file_content; ?> 结果: manongjc php css java mysql (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
