Jump to content

Writing new lines in .txt files?


random1

Recommended Posts

I have the following code:

 

$output = "test file\n output for \n\nnew lines";

 

                $outputfile = "tester.txt";

               

                // Write the file to the file system

try

{

$fh = fopen($outputfile, 'w') or die();

fwrite($fh, $output);

fclose($fh);

}

catch (Exception $ex)

{

return false;

}

// file created

return true;

 

This creates the file but with no new lines. This creates the file correctly (with new lines) when I change $outputfile to something like 'tester.htaccess'.

 

Any ideas for writing new lines '\n' to .txt text files?

Link to comment
https://forums.phpfreaks.com/topic/99171-writing-new-lines-in-txt-files/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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