HomePHP Page 2 - File Security and Resources with PHP
The Concept of a Resource - PHP
In this fourth part of an article series on working with the file and operating systems with PHP, you'll learn about file ownership and permissions, and the concept of a resource. 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).
The term "resource" is commonly attached to any entity from which an input or output stream can be initiated. Standard input or output, files, and network sockets are all examples of resources.
Newline
The newline character, which is represented by the\n character sequence, represents the end of a line within a file. Keep this in mind when you need to input or output information one line at a time. Several functions introduced throughout the remainder of this chapter offer functionality tailored to working with the newline character. Some of these functions include file(), fgetcsv(), and fgets().
End-of-File
Programs require a standardized means for discerning when the end of a file has been reached. This standard is commonly referred to as the end-of-file, or EOF, character. This is such an important concept that almost every mainstream programming language offers a built-in function for verifying whether or not the parser has arrived at the EOF. In the case of PHP, this function is feof(), described next.
feof()
int feof (string resource)
The feof() function determines whether resource's EOF has been reached. It is used quite commonly in file I/O operations. An example follows: