ຫົວວິທີ PHP file()
ການສະເໜີແລະການນໍາໃຊ້
ຫົວວິທີ file() ຈະອົດວາງບັນຊີທັງໝົດຂອງເອກະສານ.
ກັບ file_get_contents() ຄ້າຍຄືກັນຢ່າງນັ້ນແຕ່ file() ຈະບັນທຶກບັນຊີໃນສະໜາມບັນນາທິການ. ລູກບັນນາທິການໃນສະໜາມບັນນາທິການຈະຕາມກັບສະໜາມໃນເອກະສານນີ້ແລະລວມມີຄຳຜ່ານ.
ຖ້າບໍ່ສຳເລັດແລ້ວຈະຫຼັງຄືນ false。
Syntax
file(path,include_path,context)
Parameter | Description |
---|---|
path | Required. Specifies the file to be read. |
include_path | Optional. If you also want to search for files in the include_path, you can set this parameter to "1". |
context |
Optional. Specifies the environment of the file handle. context It is a set of options that can modify the behavior of the stream. If null is used, it will be ignored. |
Description
for context support was added in PHP 5.0.0.
Each line in the returned array includes a line terminator, so if you do not need a line terminator, you also need to use the rtrim() function.
Tips and Comments
Note:Starting from PHP 4.3.0, you can use file_get_contents() To read the file into a string and return it.
Note:Starting from PHP 4.3.0, file() can be used safely for binary files.
Note:If PHP cannot recognize the line ending of Macintosh files when reading files, you can activate the auto_detect_line_endings runtime configuration option.
Example
<?php print_r(file("test.txt")); ?>
Output:
Array ( [0] => Hello World. Testing testing! [1] => Another day, another line. [2] => If the array picks up this line, [3] => then is it a pickup line? )