Home >Backend Development >PHP Tutorial >How to use file function

How to use file function

藏色散人
藏色散人Original
2019-02-18 09:37:374179browse

php file() function is used to read the entire file into an array.

How to use file function

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn