


This article mainly introduces the two methods of appending content to the end of the file in PHP.
In previous articles, we have introduced you to some basic operations such as writing and reading PHP files. Friends who have learned the relevant knowledge points of PHP file processing will be easier to understand and master the operation of appending content to the end of the file in PHP. In fact, this knowledge point is very simple.
Below we will introduce to you the method of php append writing to file through simple code:
The first method: fwrite
<?php $file = fopen('1.txt','ab+'); echo fwrite($file,'韦小宝!');
As shown in the above code, we use the fwrite function to add the field content of "Wei Xiaobao" to the end of the file 1.txt.
Note: The fwrite() function is used to write files.
The original content of our 1.txt file here is:
html中文网.PHP中文网
The result of the operation in the above code is:
As you can see from the picture, we added 12 characters to 1.txt, which is the content appended above. The content of the final file is as shown in the picture above.
Note: When the fopen opening mode is ab, it means opening a binary file for reading and writing, allowing reading or appending data at the end of the file.
Second method: file_put_contents
<?php file_put_contents('1.txt', '灭绝', FILE_APPEND);
PHP adds content to the end of the file. Just master the file_put_contents method in PHP.
file_put_contents Indicates writing a string to a file. The second parameter is the content to be added.
The final result is the same as calling fopen(), fwrite() and fclose() in sequence. The content of the file after appending is as follows:PHP video tutorial on the PHP Chinese website! Welcome everyone to refer to and study!
The above is the detailed content of How to append content to the end of the file in PHP? (Pictures + Videos). For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
