How to read file contents into an array in php_PHP tutorial

WBOY
Release: 2016-07-13 10:03:16
Original
892 people have browsed it

How to read file content into array in php

This article mainly introduces how to read file content into array in php, involving functions such as file, rtrim and so on in php. and string operation skills, which have certain reference value. Friends in need can refer to it

The example in this article describes how PHP reads file content into an array. 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

?

1

2

3

4

5

6

7

8

$lines = file("/tmp/file.txt");

foreach ($lines as $line) {

$line = rtrim($line);

print("$linen");

// more statements...

}

?>

1 2

3

4 5

67 8
$lines = file("/tmp/file.txt"); foreach ($lines as $line) { $line = rtrim($line);

print("$linen");
// more statements...<🎜> <🎜>}<🎜> <🎜>?>
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/968673.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/968673.htmlTechArticleHow to read file content into an array in php. This article mainly introduces how to read file content into an array in php. , involving the operation skills of files and strings using functions such as file and rtrim in PHP, with...
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