php - Why file_put_contents() not always rewrites a file? -


i wonder, why php file_put_contents() function works in weird way.

i used in loop write logs file , fine (new lines appended if no flag specified). when started script again, re-created file.

from php doc:

if filename not exist, file created. otherwise, existing file overwritten, unless file_append flag set.

ok, question is: why (when used in 1 loop) doesn't overwrite file (without file_append flag of course)? bug or feature? :)

edit: example context of use when happened:

$logfile = dirname ( __file__ ) . '/example.log'; foreach($something1 $sth1) {     $logdata .= "something\n";     foreach($something2 $sth2) {         if($something_else) {             $logdata .= "line: \t" . $sth2 . "\n";             file_put_contents($logfile, $logdata);         }     } } 

as has been mentioned in this link under flags content(which should have read) states if file filename exists, append data file instead of overwriting it(when flag set). when flag file_append set appends , when not rewrites. hope helped you.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -