srose Posted November 13, 2008 Share Posted November 13, 2008 Hi I have this code: <?php $myFile = "addresses.txt"; $fh = fopen($myFile, 'a') or die("can't open file"); fwrite($fh, $Address); fclose($fh); $num = $num + 1; ?> $Address will store IP addresses. How can I get each new IP to go in it's own line? Is there a way of having a number go before it aswell like this: 1. xxx.xxx.xxx.xxx 2 xxx.xxx.xxx.xxx Link to comment https://forums.phpfreaks.com/topic/132629-how-to-insert-new-line-in-fwrite/ Share on other sites More sharing options...
DeanWhitehouse Posted November 13, 2008 Share Posted November 13, 2008 \n i believe Link to comment https://forums.phpfreaks.com/topic/132629-how-to-insert-new-line-in-fwrite/#findComment-689667 Share on other sites More sharing options...
srose Posted November 13, 2008 Author Share Posted November 13, 2008 I tried that but every time I loaded the site it would just display a white screen. How exactly should I type it? Link to comment https://forums.phpfreaks.com/topic/132629-how-to-insert-new-line-in-fwrite/#findComment-689674 Share on other sites More sharing options...
darkfreaks Posted November 13, 2008 Share Posted November 13, 2008 please paste the exact changes in the code so we can see how it is being used what is causing the error with /n Link to comment https://forums.phpfreaks.com/topic/132629-how-to-insert-new-line-in-fwrite/#findComment-689687 Share on other sites More sharing options...
srose Posted November 13, 2008 Author Share Posted November 13, 2008 <?php $num = 1; $myFile = "addresses.txt"; $fh = fopen($myFile, 'a') or die("can't open file"); fwrite($fh, $num)\n; fwrite($fh, $Address)\n; fclose($fh); $num = $num + 1; ?> For some reason the backslashes are not displaying but they are there. Link to comment https://forums.phpfreaks.com/topic/132629-how-to-insert-new-line-in-fwrite/#findComment-689694 Share on other sites More sharing options...
darkfreaks Posted November 13, 2008 Share Posted November 13, 2008 it needs to be <?php fwrite($fh, $Address,"\n"); ?> Link to comment https://forums.phpfreaks.com/topic/132629-how-to-insert-new-line-in-fwrite/#findComment-689699 Share on other sites More sharing options...
srose Posted November 13, 2008 Author Share Posted November 13, 2008 Hi Just tried that but now nothing gets written to the txt file. Any ideas? Link to comment https://forums.phpfreaks.com/topic/132629-how-to-insert-new-line-in-fwrite/#findComment-689716 Share on other sites More sharing options...
DeanWhitehouse Posted November 13, 2008 Share Posted November 13, 2008 <?php fwrite($fh, $Address."\n"); ?> Link to comment https://forums.phpfreaks.com/topic/132629-how-to-insert-new-line-in-fwrite/#findComment-689719 Share on other sites More sharing options...
darkfreaks Posted November 13, 2008 Share Posted November 13, 2008 Blade beat me to it oh well this will work too <?php fwrite($fh, $Address"\n");?> Link to comment https://forums.phpfreaks.com/topic/132629-how-to-insert-new-line-in-fwrite/#findComment-689722 Share on other sites More sharing options...
srose Posted November 13, 2008 Author Share Posted November 13, 2008 Hi Thanks, that's it working now. Do you know how to insert a space? Link to comment https://forums.phpfreaks.com/topic/132629-how-to-insert-new-line-in-fwrite/#findComment-689728 Share on other sites More sharing options...
aniesh82 Posted November 13, 2008 Share Posted November 13, 2008 Hello Rose, I have tested your code and is working fine here. I have changed the permission of the file (addresses.txt).. Thats all.. <?php $num = 1; $myFile = "addresses.txt"; $fh = fopen($myFile, 'a') or die("can't open file"); fwrite($fh, $num); fwrite($fh, $Address); fclose($fh); $num = $num + 1; ?> check this code.. Regards, Joseph.. Link to comment https://forums.phpfreaks.com/topic/132629-how-to-insert-new-line-in-fwrite/#findComment-689729 Share on other sites More sharing options...
DeanWhitehouse Posted November 13, 2008 Share Posted November 13, 2008 by pressing the space key, you have to do it in the variable it's self or do you mean <?php fwrite($fh, " ".$Address."\n"); ?> Link to comment https://forums.phpfreaks.com/topic/132629-how-to-insert-new-line-in-fwrite/#findComment-689730 Share on other sites More sharing options...
srose Posted November 13, 2008 Author Share Posted November 13, 2008 yes, that's it. Thank you for all your help. Link to comment https://forums.phpfreaks.com/topic/132629-how-to-insert-new-line-in-fwrite/#findComment-689735 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.