PHP fwrite Write files

Source: Internet
Author: User
Tags php write

PHP write files, PHP and ASP can be the same as the operation of the file,fwrite to write the file

Now that you know how to open and close a file, you can get the most useful part of the file operation, write! There is really only one main function that is used for writing and its logic requires fwrite.


PHP-Open File: Inbox
Before we can write information to our test file, we must use the feature open to open the file in written form.

$myFile = "TestFile.txt";
$fh = fopen ($myFile, ' w ');

PHP Write File: fwrite function www.111cn.net/phper/php.html
We can write to a text file using PHP. The Fwrite feature enables you to write data to any type of file. The first parameter of the fwrite is the file processing and its second parameter is a series of data written. Just give these two functions bits of information and you are good to go!

Below, we are writing a couple of names to our test files TestFile.txt and they separated the carriaged back.

$myFile = "TestFile.txt";
$fh = fopen ($myFile, ' w ') or Die ("can ' t open file");
$stringData = "Bobby Boppern";
Fwrite ($FH, $stringData);
$stringData = "Tracy Tannern";
Fwrite ($FH, $stringData);
Fclose ($FH);

Dollar frequency hopping variable contains the file handle TestFile.txt. The file handles knowledge of the current file pointer, which is written in the form of the beginning of the file.

We wrote to the file TestFile.txt two times. Every time we write to us send a file to the string $ stringdata, the first to load Bobby Bopper and the second to load Tresitana. When we finish writing, we close the file and use the Fclose feature.

If you open TestFile.txt in Notepad the file will look like this:

content TestFile.txt file:
Bobby bopper
Tresitana
php-file inbox: Overwrite
this te StFile.txt now contains some data that we can prove when you open an existing file for a written reply. All data contained in the file is wiped clean and you start with an empty file. In this example, we open our existing file TestFile.txt write some new data to it.

$myFile = "TestFile.txt";
$fh = fopen ($myFile, ' w ') or Die ("can ' t open file");
$stringData = "Floppy Jal Opyn ";
Fwrite ($fh, $stringData);
$stringData = "Pointy Pinton";
Fwrite ($fh, $stringData);
Fclose ($FH);

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.