note 116241 added to function.file-put-contents

From: Date: Fri, 28 Nov 2014 10:01:44 +0000
Subject: note 116241 added to function.file-put-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-201034@lists.php.net to get a copy of this message
Log custom or error messages to a file. <?php class Logger{ protected $file; protected $content; protected $writeFlag; protected $endRow; public function __construct($file,$endRow="\n",$writeFlag=FILE_APPEND) { $this->file=$file; $this->writeFlag=$writeFlag; $this->endRow=$endRow; } public function AddRow($content="",$newLines=1){ for ($m=0;$m<$newLines;$m++) { $newRow .= $this->endRow; } $this->content .= $content . $newRow; } public function Commit(){ return file_put_contents($this->file,$this->content,$this->writeFlag); } public function LogError($error,$newLines=1) { if ($error!=""){ $this->AddRow($error,$newLines); echo $error; } } } $logFileDirectoryAndName="/yourDirectory/yourFileName.xxx"; $logger = new Logger($logFileDirectoryAndName); $logger->AddRow("Your Log Message"); #log a system error and echo a message $logger->LogError(mysql_error($conn)); $logger->Commit(); ?> ---- Server IP: 72.52.91.14 Probable Submitter: 41.164.9.12 ---- Manual Page -- http://php.net/manual/en/function.file-put-contents.php Edit -- https://master.php.net/note/edit/116241 Del: integrated -- https://master.php.net/note/delete/116241/integrated Del: useless -- https://master.php.net/note/delete/116241/useless Del: bad code -- https://master.php.net/note/delete/116241/bad+code Del: spam -- https://master.php.net/note/delete/116241/spam Del: non-english -- https://master.php.net/note/delete/116241/non-english Del: in docs -- https://master.php.net/note/delete/116241/in+docs Del: other reasons-- https://master.php.net/note/delete/116241 Reject -- https://master.php.net/note/reject/116241 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201034) next »