3raser Posted February 28, 2011 Share Posted February 28, 2011 Why doesn't it add a new line when I open up index.php $fp = fopen('text.txt','w'); fwrite($fp, "Your IP: ".$_SERVER['REMOTE_ADDR']."\n"); fclose($fp); Quote Link to comment https://forums.phpfreaks.com/topic/229177-doesnt-write-to-file/ Share on other sites More sharing options...
ultraloveninja Posted February 28, 2011 Share Posted February 28, 2011 try "\r\n" Quote Link to comment https://forums.phpfreaks.com/topic/229177-doesnt-write-to-file/#findComment-1180967 Share on other sites More sharing options...
3raser Posted February 28, 2011 Author Share Posted February 28, 2011 try "\r\n" Also didn't work. :/ Quote Link to comment https://forums.phpfreaks.com/topic/229177-doesnt-write-to-file/#findComment-1180968 Share on other sites More sharing options...
ultraloveninja Posted February 28, 2011 Share Posted February 28, 2011 I know I've had this happen before. I'll have to check some resources... Quote Link to comment https://forums.phpfreaks.com/topic/229177-doesnt-write-to-file/#findComment-1180971 Share on other sites More sharing options...
3raser Posted February 28, 2011 Author Share Posted February 28, 2011 I know I've had this happen before. I'll have to check some resources... Very much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/229177-doesnt-write-to-file/#findComment-1180974 Share on other sites More sharing options...
AbraCadaver Posted February 28, 2011 Share Posted February 28, 2011 Maybe the file is not writable? error_reporting(E_ALL); ini_set('display_errors', '1'); Also, to add a newline you would use a instead of w. Quote Link to comment https://forums.phpfreaks.com/topic/229177-doesnt-write-to-file/#findComment-1180984 Share on other sites More sharing options...
3raser Posted February 28, 2011 Author Share Posted February 28, 2011 Maybe the file is not writable? error_reporting(E_ALL); ini_set('display_errors', '1'); Also, to add a newline you would use a instead of w. Returned no errors, and Still nothing. :/ Quote Link to comment https://forums.phpfreaks.com/topic/229177-doesnt-write-to-file/#findComment-1180988 Share on other sites More sharing options...
Zane Posted February 28, 2011 Share Posted February 28, 2011 When you set your file pointer $fp = fopen('text.txt','w'); That w at the end means.. Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. You want a... Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. This can all be found in the manual under fopen Quote Link to comment https://forums.phpfreaks.com/topic/229177-doesnt-write-to-file/#findComment-1180993 Share on other sites More sharing options...
3raser Posted February 28, 2011 Author Share Posted February 28, 2011 When you set your file pointer $fp = fopen('text.txt','w'); That w at the end means.. Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. You want a... Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. This can all be found in the manual under fopen Was a bit confusing...... Quote Link to comment https://forums.phpfreaks.com/topic/229177-doesnt-write-to-file/#findComment-1181001 Share on other sites More sharing options...
jcbones Posted March 1, 2011 Share Posted March 1, 2011 You could use the PHP constant. "Your IP: ".$_SERVER['REMOTE_ADDR'].PHP_EOL Quote Link to comment https://forums.phpfreaks.com/topic/229177-doesnt-write-to-file/#findComment-1181022 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.