Introduction
In this article I describe the PHP FileSystem functions file, fgetss, file_exists and file_get_contents. To learn some other filesystem functions, go to:
- FileSystem Function in PHP: PART 1
- FileSystem Function in PHP: PART 2
- FileSystem Function in PHP: PART 3
- FileSystem Function in PHP: PART 4
PHP File() Function
The PHP filesystem file function reads an entire file into an array and returns the array with each element of the array corresponding to a line of the file, with the newline still attached or returns false on failure.
Syntax
| file(path,include_path,context) |
Parameters of the file function
The parameters of the function are:
| Parameter | Description |
| path | It specifies the file to read. |
| include_path | Set this parameter to one (1), if you want to search for the file in the include_path in php.ini file as well. |
| context | It specifies a context for the file. |
Example
<?php
echo "<pre>";
print_r(file("test.txt"));
?>
Output
PHP fgetss() Function
The PHP filesystem function fgetss gets a line from the file pointer and strips the HTML and PHP tags.
Syntax
| fgetss(file,length,tags) |
Parameters of the fgetss function
The parameters of the function are:
| Parameter | Description |
| file | It specifies the file to check. |
| length | It specifies the number of bytes to read. |
| tags | It specifies what tags are not to be removed. |




Join the conversation! Your thoughts help the community grow.