Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Append New Data to the End of a File
How To Append New Data to the End of a File? - PHP Script Tips - Reading and Writing Files
✍: FYIcenter.com
If you have an existing file, and want to write more data to the end of the file, you can use the fopen($fileName, "a") function. It opens the specified file, moves the file pointer to the end of the file, and returns a file handle. The second argument "a" tells PHP to open the file for appending. Once the file is open, you can use other functions to write data to the file through this file handle. Here is a PHP script example on how to use fopen() for appending:
<?php $file = fopen("/temp/cgi.log", "a"); fwrite($file,"Remote host: 64.233.179.104.\r\n"); fclose($file); $file = fopen("/temp/cgi.log", "a"); fwrite($file,"Query string: cate=102&order=down&lang=en.\r\n"); fclose($file); ?>
This script will write the following to the file:
Remote host: 64.233.179.104. Query string: cate=102&order=down&lang=en.
As you can see, file cgi.log opened twice by the script. The first call of fopen() actually created the file. The second call of fopen() opened the file to allow new data to append to the end of the file.
2007-04-22, 4847👍, 0💬
Popular Posts:
How can a servlet refresh automatically if some new data has entered the database? You can use a cli...
How To Run a JUnit Test Class? A JUnit test class usually contains a number of test methods. You can...
. How can a servlet refresh automatically if some new data has entered the database? You can use a c...
Can two catch blocks be executed? No, once the proper catch section is executed the control goes fin...
If locking is not implemented what issues can occur? IFollowing are the problems that occur if you d...