Home arrow PHP arrow 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).

  1. File Security and Resources with PHP
  2. The Concept of a Resource
  3. Opening and Closing a File
By: Apress Publishing
Rating: starstarstarstarstar / 0
November 23, 2011

print this article



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.


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().


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.


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:

$fh = fopen("/home/www/data/users.txt", "rt");
while (!feof($fh)) echo fgets($fh);

>>> More PHP Articles          >>> More By Apress Publishing

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: