trauch Posted December 23, 2008 Share Posted December 23, 2008 Can anyone help me with a script to write the date. Im using php4 and am stuck. I have a script that adds a series of numbers and outputs it to a new file. What I want is the output to be saved (appended) to an existing file (total.txt) and instead of simply providing the number, to also include a date stamp. So each day the output would be something like - 2008-12-22;238794 Over a series of days, the resulting total.txt would look like: 2008-12-22;238794 2008-12-23;525355 2008-12-24;636633 2008-12-25;455747 Link to comment https://forums.phpfreaks.com/topic/138119-write-date-in-file-major-help-needed/ Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 date Link to comment https://forums.phpfreaks.com/topic/138119-write-date-in-file-major-help-needed/#findComment-722034 Share on other sites More sharing options...
chronister Posted December 23, 2008 Share Posted December 23, 2008 Take a look at fopen and fwrite. You can use fopen to open the file, not truncate it and place the pointer at the end of the file thereby appending to the file. Nate Link to comment https://forums.phpfreaks.com/topic/138119-write-date-in-file-major-help-needed/#findComment-722039 Share on other sites More sharing options...
cwarn23 Posted December 23, 2008 Share Posted December 23, 2008 I have made a script which should do the trick and is as follows: <? if (file_exists('dates.txt')) { $file=file_get_contents('dates.txt'); } file_put_contents('dates.txt',$file."\n".date('Y-m-d;').preg_replace('/.* (.*)/is','$1',microtime())); ?> Link to comment https://forums.phpfreaks.com/topic/138119-write-date-in-file-major-help-needed/#findComment-722070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.