Definition and usage
The file_put_contents () function writes a string to the file
Grammar
File_put_contents (File,data,mode,context)
Parameter resolution
| Parameters |
Description |
| File |
Necessary. Specifies the file to write the data to. If the file does not exist, a new file is created. |
| Data |
Optional. Specifies the data to write to the file. Can be a string, an array, or a data stream. |
| Mode |
Optional. Specifies how to open/write files. Possible values:
-
File_use_include_path
-
File_append
-
Lock_ex
|
| Context |
Optional. Specifies the environment for file handles.
The context is a set of options that modify the behavior of the stream. If NULL is used, it is ignored. |
return value
The function returns the number of bytes written to the data in the file
Example
<?php $filename = "Ceshi/2.txt"; $content = file_get_contents ($filename); Highlight_string ($content); Highlight_file ($filename); File_put_contents ($filename, $content. " Xinde ");? >
Output
Dsfsdfsafsdfdsxindexindexinde 34
This article is from the "Yan" blog, please be sure to keep this source http://suyanzhu.blog.51cto.com/8050189/1898337
Php-file_put_contents () function