PHP file() ফাংশন

সংজ্ঞা ও ব্যবহার

file() ফাংশন সমগ্র ফাইলটিকে একটি আইনসমূহে পড়ে নিয়ে আসে。

সঙ্গে file_get_contents() এর অনুরূপ, কিন্তু file() ফাংশন ফাইলটিকে একটি আইনসমূহ হিসাবে ফিরিয়ে দেয়। এই আইনসমূহের প্রত্যেকটি ফাইলের একটি সারি হিসাবে রয়েছে, যার মধ্যে একটি নিবেদনমূলক চিহ্নও রয়েছে。

যদি ব্যর্থ হয়, তবে false ফিরিয়ে দিয়েছে।

Syntax

file(path,include_path,context)
Parameter Description
path Required. Specifies the file to be read.
include_path Optional. If you also want to search for files in the include_path, you can set this parameter to "1".
context

Optional. Specifies the environment of the file handle.

context It is a set of options that can modify the behavior of the stream. If null is used, it is ignored.

Description

to context support was added in PHP 5.0.0.

Each line in the returned array includes a line ending, so if you do not need line endings, you also need to use the rtrim() function.

Tips and Comments

Note:Starting from PHP 4.3.0, you can use file_get_contents() To read the file into a string and return it.

Note:Starting from PHP 4.3.0, file() can be used safely for binary files.

Note:If PHP cannot recognize the line ending of Macintosh files when reading files, you can activate the auto_detect_line_endings runtime configuration option.

Example

<?php
print_r(file("test.txt"));
>

Output:

Array
(
[0] => Hello World. Testing testing!
[1] => Another day, another line.
[2] => If the array picks up this line,
[3] => then is it a pickup line?
)