Difference between fwrite and file_put_contents in PHP

Source: Internet
Author: User
The difference between fwrite and file_put_contents in PHP is the same: the file_put_contents () function writes a string to a file, just like calling the fopen (), fwrite (), and fclose () functions in turn.

Difference: using FILE_APPEND in the file_put_contents () function can avoid deleting the existing content in the file, that is, implementing the append function when writing multiple times to the same file.


For example:

Echo file_put_contents ("test.txt", "Hello World. Testing! ", FILE_APPEND );

File_put_contentswrite the strings into test.txt in the form of catch-up,

Fwrtie clears the previous records and only keeps the content currently written.


$ File = fopen ("test.txt", "w"); echo fwrite ($ file, "Hello World. Testing! "); Fclose ($ file );


File_put_contents () function details

Fwrtie () function description

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.