Reputation: 137
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
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
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