Copy code The code is as follows:
$file=fopen("11.txt","r")or exit("Unable to open file!");//fopen opens the file. If it does not exist, it will show that it cannot be opened.
$filesize =filesize("11.txt");//Calculate file size
echo fread($file,$filesize);//Read file
fclose($file);//Close File
fopen() example of opening a file, whether
fclose() is used or not is not reflected on the page, but if fclose() is not used, the opened file will always be occupied resource.
fopen() Open URL example:
Copy code The code is as follows:
$web="http:// www.baidu.com"; // http:// cannot be loaded without adding it
$fp=fopen($web,'r');
if($fp){
while(! feof($fp)){
echo fgets($fp);
}
}
feof() checks whether the file has reached the end, and returns 1 if it reaches the end. Returns 0;
fgets() reads line by line.
file_get_contents() example;
Copy code The code is as follows:
$web ="http:/ /www.baidu.com "
$fcontent=file_get_contents($web);
echo $fcontent;
Obviously file_get_contents() is simpler.
And during the experiment, I found that if you don’t add www. in $web ="", it will jump directly, and adding www. will load this page.
http://www.bkjia.com/PHPjc/743578.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/743578.htmlTechArticleCopy the code as follows: $file=fopen("11.txt","r")or exit(" Unable to open file!");//fopen opens the file. If it does not exist, it will show that it cannot be opened. $filesize =filesize("11.txt");//Calculation document...