In this sixth part of an eight-part series on working with the file and operating systems of a computer with PHP, you'll learn how to use PHP to write to a file and how to execute shell commands. This article is excerpted from chapter 10 of the book Beginning PHP and PostgreSQL 8: From Novice to Professional, written by W. Jason Gilmore and Robert H. Treat (Apress; ISBN: 1590595475).
This section highlights several of the functions used to output data to a file.
fwrite()
int fwrite (resource handle, string string [, int length])
The fwrite() function outputs the contents of string to the resource pointed to by handle. If the optional length parameter is provided, fwrite() will stop writing when length characters have been written. Otherwise, writing will stop when the end of the string is found. Consider this example:
Tip If the optional length parameter is not supplied to fwrite(), the magic_quotes_runtime configuration parameter will be disregarded. See Chapters 2 and 9 for more information about this parameter.
fputs()
int fputs (resource handle, string string [, int length])
The fputs() function operates identically to fwrite(). Presumably, it was incorporated into the language to satisfy the terminology preferences of C/C++ programmers.