PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY If

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY If you load fopen_exclusive.php into a browser, type some text, and click Write to file, the content should be written to filetest05.txt in your target folder, as shown in the following screenshot: If you try it again, you should get a series of error messages telling you that the file already exists. I ll show you later in the chapter how to use x mode to create a series of consecutively numbered files. Combined read/write operations with fopen() By adding a plus sign (+) after any of the previous modes, the file is opened for both reading and writing. You can perform as many read or write operations as you like and in any order until the file is closed. The difference between the combined modes is as follows: r+: The file must already exist; a new one will not be automatically created. The internal pointer is placed at the beginning, ready for reading existing content. w+: Existing content is deleted, so there is nothing to read when the file is first opened. a+: The file is opened with the internal pointer at the end, ready to append new material, so the pointer needs to be moved back before anything can be read. x+: Always creates a new file, so there s nothing to read when the file is first opened. Reading is done with fread() or fgets(), and writing with fwrite() exactly the same as before, so I won t go through each mode. What s important is to understand the position of the internal pointer. Moving the internal pointer Since reading and writing operations always start wherever the internal pointer happens to be, you normally want it to be at the beginning of the file for reading, and at the end of the file for writing.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Leave a Reply