Home > Backend Development > PHP Tutorial > Load files into array in PHP_PHP tutorial

Load files into array in PHP_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 14:52:04
Original
1016 people have browsed it

Use the file() function to load the file into the array, and each line in the file is used as an element of the array.

Example:
array_file.php:

view sourceprint? 01.<?php 02. $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; 03.?> 04.<html> 05.    <head> 06.        <title>Test Array File</title> 07.    </head> 08.    <body> 09.        <?php 10. $peoples = file($DOCUMENT_ROOT.'/test/03/people.txt'); 11. $count = count($peoples); 12. if ($count == 0) { 13. echo 'NO peoples pending. Please try again later.'; 14. } 15. for ($i = 0; $i < $count; $i++) { 16. echo $peoples[$i].'<br />'; 17.            } 18.        ?> 19.    </body> 20.</html>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371695.htmlTechArticleUse the file() function to load the file into the array, and each line in the file is used as an element of the array. Example: array_file.php: view sourceprint? 01. ?php 02. $DOCUMENT_ROOT = $_SERVER [ '...
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