note 68329 added to function.file-put-contents

From: Date: Sun, 23 Jul 2006 11:11:31 +0000
Subject: note 68329 added to function.file-put-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-115055@lists.php.net to get a copy of this message
In reply to the previous note: If you want to emulate this function in PHP4, you need to return the bytes written as well as support for arrays, flags. I can only figure out the FILE_APPEND flag and array support. If I could figure out "resource context" and the other flags, I would include those too. <? define('FILE_APPEND', 1); function file_put_contents($n, $d, $flag = false) { $mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w'; $f = @fopen($n, $mode); if ($f === false) { return 0; } else { if (is_array($d)) $d = implode($d); $bytes_written = fwrite($f, $d); fclose($f); return $bytes_written; } } ?> ---- Server IP: 216.194.113.175 Probable Submitter: 71.35.197.135 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.file-put-contents.php Edit -- http://master.php.net/note/edit/68329 Del: integrated -- http://master.php.net/note/delete/68329/integrated Del: useless -- http://master.php.net/note/delete/68329/useless Del: bad code -- http://master.php.net/note/delete/68329/bad+code Del: spam -- http://master.php.net/note/delete/68329/spam Del: non-english -- http://master.php.net/note/delete/68329/non-english Del: in docs -- http://master.php.net/note/delete/68329/in+docs Del: other reasons-- http://master.php.net/note/delete/68329 Reject -- http://master.php.net/note/reject/68329 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#115055) next »