Summary of usage of the fwrite () function for writing php files

Source: Internet
Author: User
In php, the phpfwrite () function is used to write files (which can be safely used for binary files ). Simply put, add new content to a file. This article collects and summarizes several summary about the usage of fwrite () functions in php writing files, it is helpful for everyone to understand the write function fwrite. In php, the php fwrite () function is used to write files (which can be safely used for binary files ). Simply put, add new content to a file. This article collects and summarizes several summary about the usage of fwrite () functions in php writing files, it is helpful for everyone to understand the write function fwrite.

1. detailed description of php fwrite () function file writing instances

The fwrite () function is used to write data to a file. if it is successfully executed, the number of bytes written is returned. Otherwise, FALSE is returned. Its syntax is as follows:

fwrite(file,string,length)

The file parameter specifies the open file to be written. String specifies the string to be written into the open file. Length specifies the maximum number of bytes to write. Write () writes the string content to the file pointer file. If length is specified, the write will stop after the length byte is written or the string is written.

2. instance details php fwrite () function append and line feed write

The write () function is used to write strings to a file. the number of written characters is returned successfully. otherwise, FALSE is returned. The append write of the file is not related to the fwrite function, but to the mode in which the fopen function opens the file. When fopen opens a file, if the mode parameter is set to a, it indicates that the file is appended to the file. if you want to implement line feed writing in the file, you only need to add the line break n to the place where the line feed is to be written:

3. differences between fwrite and file_put_contents in PHP

This article mainly introduces the differences between fwrite and file_put_contents in PHP. similarities: the file_put_contents () function writes a string to a file, and calls fopen (), fwrite (), and fclose () in sequence () functions are the same. 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.

4. php fwrite () function does not work when line feed is written

Many new users encounter the most common but essential problem when using the php fwrite () function, that is, line feed writing. We all know the linefeed of php: \ n, carriage return: \ r. when we need to change the line, we usually use the "\ r \ n" combination. However

Why \ n linefeed does not work when we use fwrite to write a file. This article will show you how to take a look at the following example when the php fwrite () function does not work when it is written in line feed:

[Questions and answers about fwrite () functions]

Php I used fwrite () to write a file. how does the file content change?

Php fwrite is successfully written to the file but the file has no content

Php-perform fwrite and fread operations on the same file

The above is a summary of the usage of the fwrite () function in php writing files. For more information, see other related articles in the first PHP community!

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.