Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the php fread () function

Shulou Source: shulou.com Published: 2022-06-03 10:38:04 11月13日 Update

Today, I will talk to you about how to use the php fread () function. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

The php fread () function is used to read an open file, which can read data of a specified length from the file. When reading length bytes or reading to the end of the file (EOF), it stops reading and returns the read string; syntax "fread ($handle,$length)".

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer.

PHP fread () function

The fread () function reads the open file.

The fread () function in PHP can read data of a specified length in an open file, or it can be safely used in binary files. When opening a file on a system that distinguishes binary files from text files, such as Windows, the mode parameter of the fread () function is appended with b. The syntax format of this function is as follows:

Fread ($handle,$length)

Where $handle is the file resource created by the fopen () function; $length is to read up to $length bytes.

The fread () function can read data of a specified length from a file, and when it reads $length bytes or when it reaches the end of the file (EOF), the function stops reading and returns the read string. Returns FALSE if the read fails.

Note that the fread () function reads from the current location of the file pointer. Use ftell () to find the current position of the pointer, and rewind () to play back the pointer position.

[example] use the fread () function to read the contents of the file and output it.

The running results are as follows:

In the above example, a filesize () function is used to get the file size, and the function in the fread () function is to read the entire file.

After reading the above, do you have any further understanding of how to use the php fread () function? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: File function content length position character byte pointer data binary function string end example system syntax security parameter size that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Huawei Apple MySQL Shulou Information