Home >Backend Development >PHP Tutorial >PHP file() function_PHP tutorial
PHP file() function I used the file function to write a WEB anti-virus program before. In fact, file directly reads a txt file and saves it into an array. Then I think you also know what it does. Well, file reads a file by putting the first line in the txt file into the array.
PHP file() function I used the file function to write a WEB anti-virus program before. In fact, file directly reads a txt file and saves it into an array. Then I think you also know its function. What is it? File reads a file by putting the first line in the txt file into an array
Syntax:
Definition and usage
The file() reads a file into an array.
Each array element is contained from the file, with newlines still valued.
Grammar
file(path,include_path,context)
|
Description | ||||||||
---|---|---|---|---|---|---|---|---|---|
path | File path | ||||||||
include_path | Optional. Set this parameter to '1' if you want to search files in include_path (in php.ini), and | ||||||||
context | Optional. File processing within a specified range. A context is a set of options that can modify the flow of behavior. Can be skipped with empty space. |
Tips and Instructions Tip: This feature becomes binary safe in PHP 4.3. (Meaning that both binary data such as image and character data can be written to this function). -------------------------------------------------- ------------------------------- For example
print_r(file("test.txt"));?>
Output.
Array([0] => a
[1] => b.[2] => c,[3] => d?)