Jump to content

[SOLVED] Want line break in text file


chanchelkumar

Recommended Posts

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..

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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");

?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.