g_p_java Posted January 26, 2009 Share Posted January 26, 2009 Good evening, I'm using the following code in order to write in a file : $newfile="/home/newfile.txt"; $file = fopen ($newfile, "w"); //while() //I would like to place in a while, and EOF condition, but i don't know how to do that fwrite($file, $ip); fwrite($file, $newString); fclose ($file); as i see in many fwrite examples, usually they write oonly one thing in a file. 1. I would like to write an a) IP and a b )String. The above code works, but it doesn't places any space between the IP and the string e.g. 1.2.3.4How are you? (No space between them) 2. Also, with fwrite the previous recordings get erased by the new ones. What shall i do for that? Shall i place an EOF in a while or shall i use another function? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/142515-write-into-a-file-without-erasing-previous-recordings/ Share on other sites More sharing options...
MatthewJ Posted January 26, 2009 Share Posted January 26, 2009 $newfile="/home/newfile.txt"; $file = fopen ($newfile, "a"); $output = $ip." ".$newString; fwrite($file, $output); fclose ($file); That will open the file in append mode and write the data at the end of existing data in the file. Not sure why you would need the while, maybe you could clarify Quote Link to comment https://forums.phpfreaks.com/topic/142515-write-into-a-file-without-erasing-previous-recordings/#findComment-746808 Share on other sites More sharing options...
g_p_java Posted January 26, 2009 Author Share Posted January 26, 2009 $newfile="/home/newfile.txt"; $file = fopen ($newfile, "a"); $output = $ip." ".$newString; fwrite($file, $output); fclose ($file); That will open the file in append mode and write the data at the end of existing data in the file. Not sure why you would need the while, maybe you could clarify Thanks, actually it worked! It writes at the EOF, but how am i supposed to add a '\n' for every recording? Quote Link to comment https://forums.phpfreaks.com/topic/142515-write-into-a-file-without-erasing-previous-recordings/#findComment-746854 Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 $output = $ip." ".$newString . "\n"; Quote Link to comment https://forums.phpfreaks.com/topic/142515-write-into-a-file-without-erasing-previous-recordings/#findComment-746858 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.