note 37777 added to function.fopen

From: Date: Wed, 26 Nov 2003 15:54:53 +0000
Subject: note 37777 added to function.fopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-61003@lists.php.net to get a copy of this message
Ver 4.3.1 for Windows Writing in text mode does not play nicely with Heredoc (<<<) in MS-DOS. Example: $fp= fopen('file.txt', 'wt'); fwrite($fp, <<<ENDTEXT One line of text Another line of text Last line of text\n ENDTEXT ); fclose($fp); Will write this to the file: One line of text\r\r\n Another line of text\r\r\n Last line of text\r\n The <<< heredoc is picking up the \r\n from the php file and then text mode is adding another \r. As an example of the errors this can cause, a dos batch file created this way will not work (Win98). Until stream_filter_register is available (it's PHP 5 CVS now), or text-mode is corrected (if this is deemed a bug), you use this code: function fwrite2($res,$st) { fwrite($res, str_replace("\r",'',$st)); } and change your fwrite()'s to fwrite2()'s. ---- Manual Page -- http://www.php.net/manual/en/function.fopen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37777 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37777&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37777&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#61003) next »