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); 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" 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. :/ 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... 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. 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. 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. :/ 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 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...... 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 Link to comment https://forums.phpfreaks.com/topic/229177-doesnt-write-to-file/#findComment-1181022 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.