PHP fopen()和 file_get_contents() 应用与差异。
来源:互联网 发布:一般淘宝客服打字 编辑:程序博客网 时间:2024/05/22 03:26
1
$file
=
fopen
(
"11.txt"
,
"r"
)
or
exit
(
"Unable to open file!"
);
//fopen打开文件,如果不存在就显示打不开。
2
$filesize
=
filesize
(
"11.txt"
);
//计算文件大小
3
echo
fread
(
$file
,
$filesize
);
//读取文件
4
fclose(
$file
);
//关闭文件
fopen()打开文件例子,
fclose()用不用在页面上都没有体现,但是如果不用fclose()的话,被打开的文件会一直占用资源。
fopen ( )打开网址例子:
1
$web
=
"http://www.baidu.com"
; // http:// 不加的话就无法加载
2
$fp
=
fopen
(
$web
,
'r'
);
3
if
(
$fp
){
4
while
(!
feof
(
$fp
)){
5
echo
fgets
(
$fp
);
6
}
7
}
feof()检查文件是否到末端 ,到末端返回1,没有到返回0;
fgets()是逐行读取。
file_get_contents()例子;
1
$web
=
"http://www.baidu.com "
2
$fcontent
=
file_get_contents
(
$web
);
3
echo
$fcontent
;
显然file_get_contents()更为简单。
而且在实验过程中我发现,如果在 $web =""中 不加www. 会直接跳转,加www.会在本页加载。
0 0
- PHP fopen()和 file_get_contents() 应用与差异。
- php fopen()和file_get_contents() 区别介绍
- PHP中fopen,file_get_contents,curl函数的区别和性能
- php fopen file_get_contents curl区别
- [PHP]fopen、file_get_contents、curl区别
- curl、fopen和file_get_contents区别
- curl、fopen和file_get_contents区别
- php fopen,file_get_contents,curl的区别
- PHP中fopen,file_get_contents,curl的区别
- PHP抓取外部资源函数fopen / file_get_contents / curl 的区别
- php fopen失败,读写路径错误,file_get_contents失败 文件读写
- file_get_contents fopen超时问题
- fopen、file_get_contents、curl区别
- 第三节 file_get_contents()和fopen()模拟表单提交
- php file_get_contents中context选项的应用
- fopen,file_get_contents,curl的区别
- fopen、file_get_contents方式set head
- curl、fopen/file_get_contents性能比较
- NavMesh Layers (Pro only)
- JAVA建立二叉树和3种遍历
- android usb host 读写USB设备
- Android开发之切换activity动画overridePendingTransition
- vs2005或者vs2008与vs2010共存中vs2010连接错误: invalid option: -ologo
- PHP fopen()和 file_get_contents() 应用与差异。
- ormlite 的简单应用
- CentOS修改系统默认语言与编码
- ssh/git 非常慢的解决办法
- java 集合概述
- unix高级环境编程 例子 代码实现练习 第十四章:高级IO
- Windows的Cygwin下安装SSH
- 第二章实验作业
- 【Lua】windows下使用Cygwin+NDK编译Android平台的LuaJIT库