Write file function: file_put_contents()
FILE_USE_INCLUDE_PATH : The built-in path for a copy of filename will be checked
LOCK_EX : The file will be locked
FILE_APPEND : Will be moved to the end of the file. Otherwise, the contents of the file will be cleared
Syntax:
int file_put_contents(file,data,mode,context)
Parameters | Description |
---|---|
file | Required. Specifies the file to which data is to be written. If the file does not exist, a new file is created. |
data | Optional. Specifies the data to be written to the file. Can be a string, one-dimensional array, or data stream. |
mode | Optional. How to open/write files. Possible values: FILE_USE_INCLUDE_PATH, FILE_APPEND, LOCK_EX |
context | Optional. Specifies the environment for a file handle. context is a set of options that can modify the behavior of the stream. If null is used, it is ignored. |
Return value: This function will return the number of bytes of data written to the file.
mode parameter description
The function is the same as calling fopen(), fwrite() and fclose() in sequence.
Read file function: file_get_contents()
Syntax:
string file_put_contents (path,include_path,context,start,max_length)
Description | |
---|---|
Required. Specifies the file to be read. Can be an external url | |
optional. If you also want to search for files in include_path, you can set this parameter to "1". | |
Optional. Specifies the environment for a file handle. | |
Optional. Specifies the position in the file to begin reading. This parameter is new in PHP 5.1. | |
Optional. Specifies the number of bytes to read. This parameter is new in PHP 5.1. |
The above is the detailed content of PHP file basic operation examples sharing. For more information, please follow other related articles on the PHP Chinese website!