SplFileObject
PHP Manual

SplFileObject::__construct

(PHP 5 >= 5.1.0)

SplFileObject::__constructConstruct a new file object.

Описание

SplFileObject::__construct ( string $filename [, string $open_mode = "r" [, bool $use_include_path = false [, resource $context ]]] )

Construct a new file object.

Параметри

filename

The file to read.

Съвет

Даден URL може да бъде използван като име на файл с тази функция ако fopen wrappers е включено. Виж fopen() за повече подробности относно начина, по който се задава име на файл и List of Supported Protocols/Wrappers за списък с поддържаните URL протоколи.

open_mode

The mode in which to open the file. See fopen() for a list of allowed modes.

use_include_path

Whether to search in the include_path for filename .

context

A valid context resource created with stream_context_create().

Връщани стойности

Няма връщана стойност.

Грешки/Изключения

Throws a RuntimeException if the filename cannot be opened.

Примери

Example #1 SplFileObject::__construct example

This example opens the current file and iterates over its contents line by line.

<?php
$file 
= new SplFileObject(__FILE__);
foreach (
$file as $line) {
    echo 
$line;
}
?>

Примерът по-горе ще изведе нещо подобно на:

<?php
$file = new SplFileObject(__FILE__);
foreach ($file as $line) {
    echo $line;
}
?>

Вж. също


SplFileObject
PHP Manual