SplFileObject
PHP Manual

SplFileObject::__construct

(PHP 5 >= 5.1.0)

SplFileObject::__constructساخت شی جدید فایل

Description

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

ساخت شی جدید فایل

Parameters

filename

فایل برای خواندن.

Tip

A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the List of Supported Protocols/Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.

open_mode

حالت باز کردن فایل. fopen() را برای فهرستی از حالات ممکن ببینید.

use_include_path

تعیین جستجو برای include_path filename.

context

منبع زمینه صحیح با استفاده از stream_context_create() ساخته می‌شود.

Return Values

No value is returned.

Errors/Exceptions

ایجاد RuntimeException اگر filename باز نشود.

Examples

Example #1 SplFileObject::__construct() example

این مثال فایل فعلی را باز کرده و محتوای آن را خط به خط تکرار می‌کند.

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

The above example will output something similar to:

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

See Also


SplFileObject
PHP Manual