English 中文(简体)
为什么PHP不公开+fwrite 双重文件?
原标题:why does PHP fopen + fwrite double document?

I am running PHP Version 5.3.4 with Apache/2.2.17 on Windows 7 Ultimate 32bit (IIS disabled). I been looking at the fopen modes and am well aware of what mode does what, but i can t wrap my finger around why the double posting to the txt file with a single fwrite. I ve even tried modes: w and c.

现在,我不关心的是,新数据是否预先分发或附后,只要档案中的数据没有减少现有数据。

The real question is, why does the "a" mode instead of just appending new data, it writes (duplicates) the new data to the file twice before it closes.

In php Code:

$fh = "";
if(!($fh = fopen("list.txt","x")) // if file exists, just open for writing (prepend)
   $fh = fopen("list.txt","a"); // if not exist, open just for writing (append)

fwrite($fh,"Somthing
"); // write to file (filehandle, "data")
fclose($fh); // close the file

Results:
Somthing
Somthing

SOLVED: Found the culprit: nothing was wrong with my coding. It was an html validator extension I used for Chromium under Ubuntu 10.04. This extension was apparently causing something similar to instant page reload.

最佳回答
$fh = fopen("list.txt","a");
fwrite($fh,"Somthing
"); // write to file (filehandle, "data")
fclose($fh); // close the file

your logic was not correct.

————————

问题回答

我认识到,这是老的,但这一问题仍然众所周知,还有另一个原因也可能造成这一问题。 我没有使用@robx的延伸,使我的所有延期都丧失能力,没有变化——仍然是双重的。 然而,在阅读了这一read(之后,https://bugs.chromium.org/p/chromium/issues/detail?id=64810 第16号评论认为,问题在于先发制人。 并非理想,而是删除文件标题中的“icon”链,停止双重条目。





相关问题
PHP 延伸:将一物体与 __至String

在C撰写PHP延伸版时,我想将用户用地物体(IS_OBJECT)改为“......toString”(如果它有的话),否则就会失败。 我应当使用什么?

Transfer a variable to earier point without goto

How to write this without goto: ob_start(); $a = 0; echo "START of LEFT<br />"; begin: if($a > 0) { echo "CONTENT LEFT: $a<BR />"; <VERY DIFFICULT ALGORHITM> ...

variable predefinition, moving variable to earlier point

Ok, here s the deal where I m really stuck. I use my cms with design patterns. Where s the last final output(in design template s main file: design.php ): <div>{CONTENT_HEADER}</div> &...

How do you upgrade MAMP s PHP to PHP 5.3 ?

I haven t been able to find any resources on how to do this.. Anyone have any ideas or resources?! I ve tried changing the ./configure options and I m solving things one at a time but it seems like ...

How can I send all php errors run on one page to an email?

Basically I have a single page on my site that I want any php erorrs, warnings, etc to be sent to me in an email every time the script is run. Edit: this must be code that is placed on the page, not ...

热门标签