MadnessRed Posted March 25, 2008 Share Posted March 25, 2008 ok, very simple I want to write 3 blank lines then this to the end of comments.txt echo date("l jS F, Y - h:i"); echo "<br>"; echo $_POST['name']; echo " - ("; echo getenv('REMOTE_ADDR'); echo ")"; echo "<br><br>"; echo $_POST['message']; echo "<br><hr><br>"; I know I am missing something obvious here but I wont work for me Thanks Link to comment https://forums.phpfreaks.com/topic/97873-write-a-php-ost-to-a-file/ Share on other sites More sharing options...
MadnessRed Posted March 25, 2008 Author Share Posted March 25, 2008 sorry forgot my code atm <?php $filename = 'comments.txt'; $somecontent = " echo date("l jS F, Y - h:i"); echo "<br>"; echo $_POST['name']; echo " - ("; echo getenv('REMOTE_ADDR'); echo ")"; echo "<br><br>"; echo $_POST['message']; echo "<br><hr><br>"; \n\n\n "; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } ?> Link to comment https://forums.phpfreaks.com/topic/97873-write-a-php-ost-to-a-file/#findComment-500795 Share on other sites More sharing options...
MadnessRed Posted March 26, 2008 Author Share Posted March 26, 2008 bump can anyone please help Link to comment https://forums.phpfreaks.com/topic/97873-write-a-php-ost-to-a-file/#findComment-501757 Share on other sites More sharing options...
kenrbnsn Posted March 27, 2008 Share Posted March 27, 2008 That code will give you errors and will not work. I assume you want to put everything into the "$somecontent" variable: <?php $tmp = array(); $tmp[] = date("l jS F, Y - h:i"); $tmp[] = "<br>"; $tmp[] = $_POST['name'] . " - (" . getenv('REMOTE_ADDR') .")"; $tmp[] = "<br><br>"; $tmp[] = $_POST['message']; $tmp[] = "<br><hr><br>"; $somecontent = implode("\n",$tmp) . "\n\n\n"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/97873-write-a-php-ost-to-a-file/#findComment-501784 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.