note 87209 deleted from function.echo by danbrown
| From: | danbrown@php.net | Date: | Fri, 19 Jun 2009 12:13:07 +0000 |
| Subject: | note 87209 deleted from function.echo by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-157121@lists.php.net to get a copy of this message | ||
Note Submitter: CBdeVidal.jk1 (AT) GMail (DOT) com
----
/*
I use this very handy function instead of echo most of the time. It simultaneously displays a
message to the screen and a log with a datestamp. Probably only works in Windows. I only run it
from the commandline, so I don't know how it would behave on a website.
*/
define('LOG_FILE', 'C:\Backups\Backup.log');
function message($message)
{
// If we forgot to add a new line to the end...
if (substr($message, -1) != "\n") {
// ...add it.
$message = $message . "\n";
}
echo $message;
// Log messages need a Windows line feed
$message = str_replace("\n", "\r\n", $message);
if (!$fh = @fopen(LOG_FILE, "a")) {
return FALSE;
}
// [January 1st, 1900 2:13:45pm] Message...
if (@fwrite($fh, "[".date("F jS, Y g:i:sa")."] ".$message)) {
@fclose($fh);
return TRUE;
} else {
@fclose($fh);
return FALSE;
}
}