使用file()函數將文件載入數組,文件中的每一行作為數組的一個元素。
實例:
array_file.php:
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>