myphpfreaks Posted October 20, 2007 Share Posted October 20, 2007 Really I see no contrast in the benefits between these two file modes in this book I've been reading. Any light? Quote Link to comment https://forums.phpfreaks.com/topic/74039-r-vs-w/ Share on other sites More sharing options...
redarrow Posted October 20, 2007 Share Posted October 20, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/74039-r-vs-w/#findComment-373822 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.