Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the application skills of each function in PHP file operation?

Shulou Source: shulou.com Published: 2022-06-03 04:22:36 10月04日 Update

This article introduces what are the application skills of each function in the operation of PHP files, and the content is very detailed. Interested friends can refer to it and hope to be helpful to you.

PHP language has a wide range of applications, such as the flexible use of PHP language to achieve our needs in the operation of files. Let's take a look at the usage of functions related to PHP file operations.

1. Open file: fopen ("file name", "mode")

Mode:

R: read only

Ringing: read / write

W: write only. Open and empty the contents of the file. If the file does not exist, create the file.

Read / write. Open and empty the contents of the file. If the file is not saved, the file is created.

A: append. Open and write to the end of the file. If the file does not exist, a new file is created.

Read / append. Keep the contents of the file by writing to the end of the file.

two。 Close the file: fclose ()

For example:

< ? $file=fopen("test.txt","r"); //some code be executed fclose=($file); ?>

3. Check if the end of the file has been reached: feof ()

For example: if (feof ($file)) {echo "end of file";}

4. Read the file line by line: fgets ()

For example:

File=fopen ("test.txt", "r"); while (! feof ($file)) {echo fgets ($file). "

< br/>

";} fclose ($file)

5. Read the file character by character: fgetc ()

6. Whether the file exists: file_exists (); return true if it exists, false otherwise

7. Read the file into an array: $array=file ("text.txt"), $array [0] is the * * line text, and so on. If you want to flip the entire array, for example:

$arr=array_reverse ($array)

Then * one line of text is $arr [0].

To get the number of rows in the array $array, use $num=count ($array)

To determine that the text database is not empty, use: if ($num > 0) {}

Calculate the total number of pages: $total=ceil ($num/$pagesize) $pagesize is the number of messages displayed per page.

Calculate the record number of * displayed on the current page: $number= ($page-1) * $pagesize

Use "" as a delimiter to separate the data for each $number unit in the array $arr and assign this data to the array $rom

For ($iSuppli

Tags: File content data array function application terminal application skill skill unit that is text more pattern language help good one line information interest Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Linux vpn Xiaomi Redmi