Answer the question
In order to leave comments, you need to log in
Functions in php?
Hello.
With etude programming. Faced such a problem.
Made a simple function to write to a file.
function writtetwoLog(){
$entry_line = "$dtime - Сайт все еще не доступен \n";
$fp = fopen("logs.txt", "a");
fputs($fp, $entry_line);
fclose($fp);
}
Answer the question
In order to leave comments, you need to log in
function writtetwoLog($dtime){
$entry_line = "$dtime - Сайт все еще не доступен \n";
$fp = fopen("logs.txt", "a");
fputs($fp, $entry_line);
fclose($fp);
}
writtetwoLog($dtime);
// $dtime = ...
function writtetwoLog(){
global $dtime;
$entry_line = "$dtime - Сайт все еще не доступен \n";
$fp = fopen("logs.txt", "a");
fputs($fp, $entry_line);
fclose($fp);
}
1) all variables must be passed into the function explicitly. Avoid using global variables.
2) if $dtime
it is the logging function that is needed (it is part of the log format), and this is the current time (usually we need to remember when we wrote it to the log), then we can simply get the current time inside the function.
3) if $dtime
this is not the current time, but just some kind of variable, add it to the message and pass it inside:
function log($message) {
// ...
}
log("$dtime - Сайт все еще не доступен");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question