PHP output to a textfile

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mwalimo
Forum Newbie
Posts: 5
Joined: Sat Jun 13, 2009 11:42 am

PHP output to a textfile

Post by mwalimo »

How do I make the content of 'data.txt'
1
23
i.e on two lines NOT on one line as 123?

(see php script below write the out)

I am on Windows VISTA, running a WAMP server.


<?php
$fp = fopen('data.txt', 'w');
fwrite($fp, '1');
fwrite($fp, '23');
fclose($fp);

// the content of 'data.txt' is now 123 and not 23!
?>
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: PHP output to a textfile

Post by Mark Baker »

Write a newline character

Code: Select all

 
$fp = fopen('data.txt', 'w');
fwrite($fp, '1');
fwrite($fp, PHP_EOL);
fwrite($fp, '23');
fclose($fp);
 
Post Reply