chanchelkumar Posted August 17, 2009 Share Posted August 17, 2009 Hi all, I am trying to write a list of things in to file.. i want this as line by line.. but this happens in one single line.. $myFile = "menu/menu.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "Floppy Jalopy\n"; fwrite($fh, $stringData); $stringData = "Pointy Pinto\n"; fwrite($fh, $stringData); fclose($fh); This is my code.. can any one help me.. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 17, 2009 Share Posted August 17, 2009 Well for starters, what operating system are you using? Also, what program are you using to view the results? If you use a web browser to look at the file, you might well get everything all on one line if it treats it as HTML rather than a text file (i'm unsure if browsers will be doing this -- i'd expect most would assume it's a text file, but it's a possibility) Quote Link to comment Share on other sites More sharing options...
DarkendSoul Posted August 17, 2009 Share Posted August 17, 2009 If on linux generally it's "\n" for a new line. For windows programs it tends to be "\r\n". If you're trying to get line breaks in HTML you need to make them <br /> (XHTML Strict) or <br> (Other). If you want to make it so in a browser "\n" is a line break you send headers with PHP before you display the content. <?php header('Content-Type: text/plain'); echo get_file_contents(dirname(__FILE__) . "./menu/menu.txt"); ?> Quote Link to comment Share on other sites More sharing options...
chanchelkumar Posted August 17, 2009 Author Share Posted August 17, 2009 Thanks DarkendSoul, it works... Quote Link to comment 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.