note 87209 added to function.echo

From: Date: Mon, 24 Nov 2008 20:47:55 +0000
Subject: note 87209 added to function.echo
Groups: php.notes 
Request: Send a blank email to php-notes+get-146893@lists.php.net to get a copy of this message
/* 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; } } ---- Server IP: 209.41.74.194 Probable Submitter: 63.95.64.254 ---- Manual Page -- http://www.php.net/manual/en/function.echo.php Edit -- https://master.php.net/note/edit/87209 Del: integrated -- https://master.php.net/note/delete/87209/integrated Del: useless -- https://master.php.net/note/delete/87209/useless Del: bad code -- https://master.php.net/note/delete/87209/bad+code Del: spam -- https://master.php.net/note/delete/87209/spam Del: non-english -- https://master.php.net/note/delete/87209/non-english Del: in docs -- https://master.php.net/note/delete/87209/in+docs Del: other reasons-- https://master.php.net/note/delete/87209 Reject -- https://master.php.net/note/reject/87209 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146893) next »