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.
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: