The fclose() function closes an open file pointer. The function returns TRUE on success and FALSE on failure.
Syntax
fclose(file_pointer)
Parameters
file_pointer − The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen().
Return
The fclose() function returns.
- TRUE on success
- FALSE on failure
Example
<?php $file_pointer = fopen('amit.txt', 'r'); fclose($file_pointer); ?>
Output
true
Let us see another example. This shows a file which is opened, the content is returned using fgetsss and the file is closed with file pointer using file pointer.
Example
<?php $file_pointer = @fopen("/documents/new.php", "r"); if ($file_pointer) { while (!feof($file_pointer)) { $buffer = fgetss($file_pointer, 1024); echo $buffer; } fclose($file_pointer); } ?>
Output
This is demo text