网络编程 
首页 > 网络编程 > 浏览文章

php实现以只读方式打开文件的方法

(编辑:jimmy 日期: 2024/5/31 浏览:3 次 )

本文实例讲述了php实现以只读方式打开文件的方法。分享给大家供大家参考。具体分析如下:

php中可以通过fopen()打开一个文件,第二个参数设置为"r"表示已只读方式打开,函数返回一个文件句柄,其它函数就可以通过这个文件句柄对文件进行不同方式的读取

<"/tmp/file.txt", "r");
print("Type of file handle: " . gettype($file) . "\n");
print("The first line from the file handle: " . fgets($file));
fclose($file); 
"color: #0000ff">Type of file handle: resource
The first line from the file handle: Welcome to sharejs.com php tutorials

文件读取完成后,需要使用fclose()函数关闭文件句柄,以释放资源

希望本文所述对大家的php程序设计有所帮助。

上一篇:php读取文件内容到数组的方法
下一篇:php实现在服务器上创建目录的方法
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网