Jump to content

R+ vs W+


myphpfreaks

Recommended Posts

standard option

 

These three basic ways to open a file have distinct purposes. If you want to get information out of a file, like search an e-book for the occurrences of "cheese", then you would open the file for read only.

 

If you wanted to write a new file, or overwrite an existing file, then you would want to open the file with the "w" option. This would wipe clean all existing data within the file.

 

If you wanted to add the latest order to your "orders.txt" file, then you would want to open it to append the data on to the end. This would be the "a" option.

 

advance option

 

There are additional ways to open a file. Above we stated the standard ways to open a file. However, you can open a file in such a way that reading and writing is allowable! This combination is done by placing a plus sign "+" after the file mode character.

 

Read/Write: 'r+'

Opens a file so that it can be read from and written to. The file pointer is at the beginning of the file.

 

Write/Read: 'w+'

This is exactly the same as r+, except that it deletes all information in the file when the file is opened.

 

Append: 'a+'

This is exactly the same as r+, except that the file pointer is at the end of the file.

 

Link to comment
https://forums.phpfreaks.com/topic/74039-r-vs-w/#findComment-373822
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.