Home > Backend Development > PHP Tutorial > How to read file contents into an array in php_PHP tutorial

How to read file contents into an array in php_PHP tutorial

WBOY
Release: 2016-07-13 10:03:37
Original
995 people have browsed it

How to read file content into an array in php,

The example in this article describes how to read file content into an array in php. Share it with everyone for your reference. The specific analysis is as follows:

In PHP, files can be read into an array through the file() function. The elements in the array are each line of the file. The file() function uses "n" to split the file by line and save it to the array, so each of the arrays The elements all end with "n", we can remove them through the rtrim() function

<&#63;php 
$lines = file("/tmp/file.txt");
foreach ($lines as $line) {
 $line = rtrim($line);
 print("$line\n");
 // more statements...
}
&#63;>
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/968254.htmlTechArticleHow to read file content into an array in php. This article describes the method of reading file content into an array in php. Share it with everyone for your reference. The specific analysis is as follows: In php, you can pass f...
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