Tarek Siddiki
Tarek Siddiki

Reputation: 137

how to add new line on an created text file ?(php)

i am working on a php script. it is as follows:

<?
$a='a b c d e';
$b=explode(" ",$a);
foreach ($b as $c) {

$filename = 'test.txt';
$fp = fopen($filename, "a+");
$write = fputs($fp, $c."/n");
fclose($fp);

}
?>

the output (test.txt) comes as this:

a/nb/nc/nd/ne/n

But I want to get the text file like this:

a
b
c
d
e

can any body tell me how to do this?

Upvotes: 1

Views: 31213

Answers (2)

user3186859
user3186859

Reputation: 41

on line 8 you can add \n\r

This will make it cross platform from Windows/MAC/LINUX/UNIX.

eg. $write = fputs($fp, $c."\r\n");

Upvotes: 4

HorusKol
HorusKol

Reputation: 8706

Escape sequences are indicated with a \ not / - so you need to use "\n" to put a newline into your string (and file)

Upvotes: 9

Related Questions