复制代码 代码如下:
$file=fopen("11.txt","r")or exit("Unable to open file!");//fopen打开文件,如果不存在就显示打不开。
$filesize =filesize("11.txt");//计算文件大小
echo fread($file,$filesize);//读取文件
fclose($file);//关闭文件
fopen()打开文件例子,
fclose()用不用在页面上都没有体现,但是如果不用fclose()的话,被打开的文件会一直占用资源。
fopen() 打开网址例子:
复制代码 代码如下:
$web="http://www.baidu.com"; // http:// 不加的话就无法加载
$fp=fopen($web,'r');
if($fp){
while(!feof($fp)){
echo fgets($fp);
}
}
feof()检查文件是否到末端 ,到末端返回1,没有到返回0;
fgets()是逐行读取。
file_get_contents()例子;
复制代码 代码如下:
$web ="http://www.baidu.com "
$fcontent=file_get_contents($web);
echo $fcontent;
显然file_get_contents()更为简单。
而且在实验过程中我发现,如果在 $web =""中 不加www. 会直接跳转,加www.会在本页加载。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver CS6
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
