Page 1 of 1

PHP output to a textfile

Posted: Sat Jun 13, 2009 11:48 am
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!
?>

Re: PHP output to a textfile

Posted: Sat Jun 13, 2009 3:46 pm
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);