Copy Code code as follows:
$file =fopen ("11.txt", "R") or exit ("Unable to open file!"); /fopen Open the file, if it does not exist, the display will not open.
$filesize =filesize ("11.txt");//Calculate File size
Echo fread ($file, $filesize);//Read file
Fclose ($file);//Close file
fopen () Opens the file example,
Fclose () is not shown on the page, but if you do not use the fclose (), the file being opened will always occupy resources.
fopen () Open URL Example:
Copy Code code as follows:
$web = "http://www.baidu.com"; http://can't load if you don't add it.
$FP =fopen ($web, ' R ');
if ($fp) {
while (!feof ($fp)) {
Echo fgets ($FP);
}
}
Feof () Check whether the file to the end, to the end to return 1, not to return 0;
Fgets () is read-by-line.
File_get_contents () example;
Copy Code code as follows:
$web = "Http://www.baidu.com"
$fcontent =file_get_contents ($web);
Echo $fcontent;
Obviously file_get_contents () is much simpler.
And in the course of the experiment I found that if the $web = "" is not added to the www. Will jump directly, plus www. will be loaded on this page.