Bug #51640 [Com]: Fwrite writes twice a text
| From: | g_i_ivanov at mail dot bg | Date: | Tue, 01 Jun 2010 08:19:48 +0000 |
| Subject: | Bug #51640 [Com]: Fwrite writes twice a text | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-150983@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=51640&edit=1
ID: 51640
Comment by: g_i_ivanov at mail dot bg
Reported by: spiderboy1989 at gmail dot com
Summary: Fwrite writes twice a text
Status: Open
Type: Bug
Package: Filesystem function related
Operating System: Windows XP
PHP Version: 5.3.2
New Comment:
I have the same problem:
Windows XP Professional SP3, Apache/2.2.14, PHP 5.2.13 (cli)
code:
------------------------------------------
$fp = fopen("d:/Projects/test/logs/testfile.txt", "a");
fwrite($fp, date('c') . " - Sample text" . PHP_EOL);
fclose($fp);
result:
------------------------------------------
2010-05-31T10:36:37+03:00 - Sample text
2010-05-31T10:36:37+03:00 - Sample text
Previous Comments:
------------------------------------------------------------------------
[2010-04-23 01:57:42] spiderboy1989 at gmail dot com
Description:
------------
I'm having troubles with fwrite() function. It is writing twice a text I
just need to write once. I searched in google for the same problem, and
I found the same bug reported here :
http://bugs.php.net/bug.php?id=21916, and here :
http://bugs.php.net/bug.php?id=16225, but
neither of both was solved.
This is how it writes into the file :
"First
Second
Hello world!
Hello world!
Third"
As you can see, the string "hello world!" is writed twice, and that
should not happen. Also, and this is weird, the line fwrite($op,
$lastLine); prints the text correctly, just once...
Test script:
---------------
$file = "test.txt";
$string = "Hello world!\r\n";
$op = fopen($file,"r+");
$exp = explode("\n", fread($op, filesize($file)));
$lastLine = end($exp);
fseek($op, -strlen($lastLine), SEEK_END);
fwrite($op, $string);
fwrite($op, $lastLine);
fclose($op);
Expected result:
----------------
The text should be writed just once.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51640&edit=1