note 91793 added to function.file-put-contents

From: Date: Thu, 25 Jun 2009 15:57:58 +0000
Subject: note 91793 added to function.file-put-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-157500@lists.php.net to get a copy of this message
file_put_contents() strips the last line ending If you really want an extra line ending at the end of a file when writing with file_put_contents(), you must append an extra PHP_EOL to the end of the line as follows. <?php $a_str = array("these","are","new","lines"); $contents = implode(PHP_EOL, $a_str); $contents .= PHP_EOL . PHP_EOL; file_put_contents("newfile.txt", $contents); print("|$contents|"); ?> You can see that when you print $contents you get two extra line endings, but if you view the file newfile.txt, you only get one. ---- Server IP: 208.69.120.35 Probable Submitter: 156.56.18.136 ---- Manual Page -- http://www.php.net/manual/en/function.file-put-contents.php Edit -- https://master.php.net/note/edit/91793 Del: integrated -- https://master.php.net/note/delete/91793/integrated Del: useless -- https://master.php.net/note/delete/91793/useless Del: bad code -- https://master.php.net/note/delete/91793/bad+code Del: spam -- https://master.php.net/note/delete/91793/spam Del: non-english -- https://master.php.net/note/delete/91793/non-english Del: in docs -- https://master.php.net/note/delete/91793/in+docs Del: other reasons-- https://master.php.net/note/delete/91793 Reject -- https://master.php.net/note/reject/91793 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157500) next »