Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Fopen() and file_get_contents() in PHP are applications and differences.

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains that "fopen () and file_get_contents () in PHP are applications and differences". The explanation in this article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "fopen () and file_get_contents () in PHP are applications and differences."

The copy code is as follows:

$file=fopen ("11.txt", "r") or exit ("Unable to open file!"); / / fopen opens the file and shows that it cannot be opened if it does not exist.

$filesize = filesize ("11.txt"); / / calculate the file size

Echo fread ($file,$filesize); / / read the file

Fclose ($file); / / close the file

Example of fopen () opening a file

Whether fclose () is used or not is not reflected on the page, but if you don't use fclose (), the opened file will always take up resources.

Example of fopen () opening a URL:

The copy 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 reaches the end, returns 1 to the end, and does not return 0

Fgets () is read line by line.

File_get_contents () example

The copy code is as follows:

$web = "http://www.baidu.com"

$fcontent=file_get_contents ($web)

Echo $fcontent

Obviously file_get_contents () is simpler.

And in the course of the experiment, I found that if you don't add www in $web = "". Will jump directly, add www. Will be loaded on this page.

Thank you for your reading, the above is the content of "fopen () and file_get_contents () in PHP is the introduction of applications and differences". After the study of this article, I believe you have a deeper understanding of the introduction of applications and differences between fopen () and file_get_contents () in PHP, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report