Jump to content

Writing to a file


bobpatel07

Recommended Posts

I am a new to php.  I am trying to writing to a text file using php.  I am able to write to the text file, however when I open the text file using the text editor, it displays raw data on the same line. 

 

How can I write data in a text file on the next line?

 

Following is my php code.

 

<?php

$myFile = "testFile.txt";

$fh = fopen($myFile, 'w') or die("can't open file");

$stringData = "Bobby Bopper\n";

fwrite($fh, $stringData);

$stringData = "Tracy Tanner\n";

fwrite($fh, $stringData);

print "Date is written";

fclose($fh);

?>

 

Text file

 

Bobby BopperTracy Tanner

 

// I used notepad to view.  I am also using WAMP server

 

Link to comment
https://forums.phpfreaks.com/topic/194000-writing-to-a-file/
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.