* Thus wrote Corey Hitchcock: > Hi, I'm relatively new with php but I have a question about this 'new' > function. If I use file_put_contents("file.txt", "whatever") then it, of > course, writes "whatever" in the "file.txt". If I later do the same thing > but put a different word (say "other") from "whatever" then it overwrites > that entry in the file. This is still fine (and expected), however, if I use > this file_put_contents("file.txt", "whatever", FILE_APPEND) then it appends > like expected BUT there are two entries. For example, the file would look > like this: whateverwhateverotherother. Am I missing something here? I want > it to append but I don't want the double entries. There is a Resource > Context but I don't know what that's for (or what is a valid entry for it). > Thank you for any assistance you can offer in clearing up this confusion and > I look forward to hearing from you in the near future.
put_contents.php: <?php file_put_contents("file.txt", "text1", FILE_APPEND); file_put_contents("file.txt", "text2", FILE_APPEND); ?> % rm file.txt % php put_contents.php % cat file.txt text1text2 The first time you use it, you probably shouldn't use the FILE_APPEND option. When I run it again: % php put_contents.php % cat file.txt text1text2text1text2 Curt -- First, let me assure you that this is not one of those shady pyramid schemes you've been hearing about. No, sir. Our model is the trapezoid! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php