PHP fopen () and file

Source: Internet
Author: User
Tags url example

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.