English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP file() Function Usage and Example

PHP Filesystem Reference Manual

The file() function reads the entire file into an array, with each element being the corresponding line from the file, including newline characters.

Syntax

array file ( string $filename [, int $flags = 0 [, resource $context ]])

Online Example

<?php
   print_r(file("/PhpProject/sample.txt"));
?>

Output Result

Array
(
    [0] => oldtoolbag.com
    [1]]=> www.oldtoolbag.com
    [2]]=> TP
)

PHP Filesystem Reference Manual