This article mainly introduces PHP fopen () and file_get_contents () application and difference, need friends can refer to the following
The code is 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");//Compute File size echo fread ($file, $filesize);//Read file fclose ($file)//Close file fopen () Open File example, Fclo SE () is not available on the page, but if you do not use the fclose (), the file being opened will always occupy resources. fopen () Open URL Example: The code is as follows: $web = "http://www.baidu.com"; http://Cannot load $fp =fopen ($web, ' r ') without adding words; if ($FP) {while (!feof ($fp)) {echo fgets ($FP); Feof () checks whether the file is to the end, returns 1 to the end, does not return 0, and fgets () is read-by-row. File_get_contents () example; The code is 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.