Writing to a file

A

Anonymous

Guest
Hi,

Can anybody explain me why, when you have:

$file = fopen('file.txt','w+');
$data = '';

for($i=0; $i<11; $i++){
$data .= $i.'='.$i.'\n';
}
fwrite($file, $data);

The output generated to data will be all in one sentence, such as: 1=1\n2=2\n3=3\n and so on?

If, instead, you have $data .= $i.'='.$i."\n";
The output generated is:
1=1
2=2
3=3

Why is this difference?

Thanks in advance
 
victor123 said:
Hi,

Can anybody explain me why, when you have:

$file = fopen('file.txt','w+');
$data = '';

for($i=0; $i<11; $i++){
$data .= $i.'='.$i.'\n';
}
fwrite($file, $data);

The output generated to data will be all in one sentence, such as: 1=1\n2=2\n3=3\n and so on?

If, instead, you have $data .= $i.'='.$i."\n";
The output generated is:
1=1
2=2
3=3

Why is this difference?

Thanks in advance
next string \n be parsed only in doublequotes "\n" in '\n' singlequotes \n and e.t.c. is not working.
By the way string declared in singlequotes is faset about it say php Creator
 
Thanks, wizard. Could you please explain your last sentence? i didn't quite get it.
 
victor123 said:
Thanks, wizard. Could you please explain your last sentence? i didn't quite get it.
Examples:
$str = 'This is PHP string'; - faser than
$str = "This is PHP string";
 
Back
Top