Summary of Usage of PHP fclose Function

  • 2021-11-24 01:06:36
  • OfStack

php fclose () Function Syntax

Function: Close 1 open file

Syntax:


fclose(file)

Parameters:

file required. Documents that are required to be closed.

Note: If successful, true is returned, otherwise, false is returned. The file pointer must be valid and successfully opened via fopen () or fsockopen ().

Example of php fclose () Function


<?php
$file = fopen("./test.txt","r");
echo fclose($file);
?>

PHP Warning: fclose (): How

I replaced r with r + and w with w +.
$file_name = './inc/const. php'; //File to replace operation
@ $fp = fopen ($file_name, 'r +'); //Open the file to be replaced
@$conf_file = fread($fp,filesize($file_name));
$conf_file = preg_replace("/httpurl\s*\=\s(\'|\")(.*?)(\"|')/","httpurl = \"" . $httpurl. "\"",$conf_file);
$conf_file = preg_replace("/databasePrefix\s*\=\s(\'|\")(.*?)(\"|')/","databasePrefix = \"" . $databasePrefix. "\"",$conf_file);
fclose(@$fp);
@$fp = fopen($file_name,'w+');
$fw = fwrite($fp, trim($conf_file));
fclose($fp);
This should work, otherwise get rid of @.


Related articles: