


Introduction to the Application and Differences of PHP fopen() and file_get_contents()_PHP Tutorial
$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:
$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;
$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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To learn more about open source, please visit: 51CTO Hongmeng Developer Community https://ost.51cto.com Running environment DAYU200:4.0.10.16SDK: 4.0.10.15IDE: 4.0.600 1. To create an application, click File- >newFile->CreateProgect. Select template: [OpenHarmony] EmptyAbility: Fill in the project name, shici, application package name com.nut.shici, and application storage location XXX (no Chinese, special characters, or spaces). CompileSDK10, Model: Stage. Device

Use Java's File.length() function to get the size of a file. File size is a very common requirement when dealing with file operations. Java provides a very convenient way to get the size of a file, that is, using the length() method of the File class. . This article will introduce how to use this method to get the size of a file and give corresponding code examples. First, we need to create a File object to represent the file we want to get the size of. Here is how to create a File object: Filef

How to convert php blob to file: 1. Create a php sample file; 2. Through "function blobToFile(blob) {return new File([blob], 'screenshot.png', { type: 'image/jpeg' })} ” method can be used to convert Blob to File.

How to solve PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectory In the process of using PHP development, we often encounter some file operation problems, one of which is "PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectory"

Use Java's File.renameTo() function to rename files. In Java programming, we often need to rename files. Java provides the File class to handle file operations, and its renameTo() function can easily rename files. This article will introduce how to use Java's File.renameTo() function to rename files and provide corresponding code examples. The File.renameTo() function is a method of the File class.

If you are an IT administrator or technology expert, you must be aware of the importance of automation. Especially for Windows users, Microsoft PowerShell is one of the best automation tools. Microsoft offers a variety of tools for your automation needs, without the need to install third-party applications. This guide will detail how to leverage PowerShell to automate tasks. What is a PowerShell script? If you have experience using PowerShell, you may have used commands to configure your operating system. A script is a collection of these commands in a .ps1 file. .ps1 files contain scripts executed by PowerShell, such as basic Get-Help

How to solve PHPWarning:fopen():SSLoperationfailedinfile.phponlineX In PHP programming, we often use the fopen function to open files or URLs and perform related operations. However, when using the fopen function, sometimes you will encounter something similar to Warning:fopen():SSLoperationfailedinfile.p

How to solve PHPWarning:fopen():failedtoopenstream:Permissiondenied In the process of developing PHP programs, we often encounter some error messages, such as PHPWarning:fopen():failedtoopenstream:Permissiondenied. This error is usually due to incorrect file or directory permissions
