How to use file function

藏色散人
Release: 2023-04-05 09:36:02
Original
4107 people have browsed it

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)
Copy after login

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);
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!