Home >Backend Development >PHP Tutorial >How to use file function
php file() function is used to read the entire file into an array.
php file() function Syntax
Function: Read the entire file into an array.
Syntax:
file(path,include_path,context)
Parameters:
path Required. Specifies the file to be read.
include_path Optional. If you also want to search for files in include_path, you can set this parameter to "1".
context Optional. Specifies the environment for a file handle. context is a set of options that can modify the behavior of the stream. If null is used, it is ignored.
Note: Each row in the returned array includes line terminators, so if line terminators are not required, you need to use the rtrim() function.
php file() function example
<?php $txt = file("./test.txt"); print_r($txt); ?>
This article is an introduction to the PHP file function. I hope it will be helpful to friends in need!
The above is the detailed content of How to use file function. For more information, please follow other related articles on the PHP Chinese website!